Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add a ugnot constant #2656

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contribs/gnodev/cmd/gnodev/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gnolang/gno/contribs/gnodev/pkg/address"
"github.com/gnolang/gno/contribs/gnodev/pkg/dev"
"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
"github.com/gnolang/gno/tm2/pkg/std"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (va varPremineAccounts) String() string {

func generateBalances(bk *address.Book, cfg *devCfg) (gnoland.Balances, error) {
bls := gnoland.NewBalances()
premineBalance := std.Coins{std.NewCoin("ugnot", 10e12)}
premineBalance := std.Coins{std.NewCoin(ugnot.Denom, 10e12)}

entries := bk.List()

Expand Down
5 changes: 3 additions & 2 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gnolang/gno/contribs/gnodev/pkg/emitter"
"github.com/gnolang/gno/contribs/gnodev/pkg/events"
"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/gno.land/pkg/integration"
"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/amino"
Expand Down Expand Up @@ -52,7 +53,7 @@ func DefaultNodeConfig(rootdir string) *NodeConfig {
balances := []gnoland.Balance{
{
Address: defaultDeployer,
Amount: std.Coins{std.NewCoin("ugnot", 10e12)},
Amount: std.Coins{std.NewCoin(ugnot.Denom, 10e12)},
},
}

Expand Down Expand Up @@ -87,7 +88,7 @@ type Node struct {
currentStateIndex int
}

var DefaultFee = std.NewFee(50000, std.MustParseCoin("1000000ugnot"))
var DefaultFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))

func NewDevNode(ctx context.Context, cfg *NodeConfig) (*Node, error) {
mpkgs, err := NewPackagesMap(cfg.PackagesPathList)
Expand Down
5 changes: 3 additions & 2 deletions contribs/gnodev/pkg/dev/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/gnolang/gno/contribs/gnodev/pkg/events"
"github.com/gnolang/gno/gno.land/pkg/gnoclient"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/gno.land/pkg/integration"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
core_types "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
Expand Down Expand Up @@ -246,8 +247,8 @@ func testingCallRealm(t *testing.T, node *Node, msgs ...gnoclient.MsgCall) (*cor
}

txcfg := gnoclient.BaseTxCfg{
GasFee: "1000000ugnot", // Gas fee
GasWanted: 2_000_000, // Gas wanted
GasFee: ugnot.ValueString(1000000), // Gas fee
GasWanted: 2_000_000, // Gas wanted
}

return cli.Call(txcfg, msgs...)
Expand Down
74 changes: 51 additions & 23 deletions contribs/gnodev/pkg/dev/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/gnolang/gno/contribs/gnodev/pkg/address"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/stretchr/testify/assert"
Expand All @@ -26,33 +27,60 @@ func TestResolvePackagePathQuery(t *testing.T) {
ExpectedPackagePath PackagePath
ShouldFail bool
}{
{".", PackagePath{
{
Path: ".",
}, false},
{"/simple/path", PackagePath{
ExpectedPackagePath: PackagePath{
Path: ".",
},
},
{
Path: "/simple/path",
}, false},
{"/ambiguo/u//s/path///", PackagePath{
Path: "/ambiguo/u/s/path",
}, false},
{"/path/with/creator?creator=testAccount", PackagePath{
Path: "/path/with/creator",
Creator: testingAddress,
}, false},
{"/path/with/deposit?deposit=100ugnot", PackagePath{
Path: "/path/with/deposit",
Deposit: std.MustParseCoins("100ugnot"),
}, false},
{".?creator=g1hr3dl82qdy84a5h3dmckh0suc7zgwm5rnns6na&deposit=100ugnot", PackagePath{
Path: ".",
Creator: testingAddress,
Deposit: std.MustParseCoins("100ugnot"),
}, false},
ExpectedPackagePath: PackagePath{
Path: "/simple/path",
},
},
{
Path: "/ambiguo/u//s/path///",
ExpectedPackagePath: PackagePath{
Path: "/ambiguo/u/s/path",
},
},
{
Path: "/path/with/creator?creator=testAccount",
ExpectedPackagePath: PackagePath{
Path: "/path/with/creator",
Creator: testingAddress,
},
},
{
Path: "/path/with/deposit?deposit=" + ugnot.ValueString(100),
ExpectedPackagePath: PackagePath{
Path: "/path/with/deposit",
Deposit: std.MustParseCoins(ugnot.ValueString(100)),
},
},
{
Path: ".?creator=g1hr3dl82qdy84a5h3dmckh0suc7zgwm5rnns6na&deposit=" + ugnot.ValueString(100),
ExpectedPackagePath: PackagePath{
Path: ".",
Creator: testingAddress,
Deposit: std.MustParseCoins(ugnot.ValueString(100)),
},
},

// errors cases
{"/invalid/account?creator=UnknownAccount", PackagePath{}, true},
{"/invalid/address?creator=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", PackagePath{}, true},
{"/invalid/deposit?deposit=abcd", PackagePath{}, true},
{
Path: "/invalid/account?creator=UnknownAccount",
ShouldFail: true,
},
{
Path: "/invalid/address?creator=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
ShouldFail: true,
},
{
Path: "/invalid/deposit?deposit=abcd",
ShouldFail: true,
},
}

for _, tc := range cases {
Expand Down
13 changes: 7 additions & 6 deletions gno.land/cmd/gnoland/genesis_balances_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
Expand Down Expand Up @@ -57,13 +58,13 @@ func (c *balancesAddCfg) RegisterFlags(fs *flag.FlagSet) {
&c.balanceSheet,
"balance-sheet",
"",
"the path to the balance file containing addresses in the format <address>=<amount>ugnot",
"the path to the balance file containing addresses in the format <address>=<amount>"+ugnot.Denom,
)

fs.Var(
&c.singleEntries,
"single",
"the direct balance addition in the format <address>=<amount>ugnot",
"the direct balance addition in the format <address>=<amount>"+ugnot.Denom,
)

fs.StringVar(
Expand Down Expand Up @@ -167,7 +168,7 @@ func execBalancesAdd(ctx context.Context, cfg *balancesAddCfg, io commands.IO) e
io.Println()

for address, balance := range finalBalances {
io.Printfln("%s:%dugnot", address.String(), balance)
io.Printfln("%s:%d%s", address.String(), balance, ugnot.Denom)
}

return nil
Expand Down Expand Up @@ -208,7 +209,7 @@ func getBalancesFromTransactions(
}

feeAmount := std.NewCoins(tx.Fee.GasFee)
if feeAmount.AmountOf("ugnot") <= 0 {
if feeAmount.AmountOf(ugnot.Denom) <= 0 {
io.ErrPrintfln(
"invalid gas fee amount encountered: %q",
tx.Fee.GasFee.String(),
Expand All @@ -223,7 +224,7 @@ func getBalancesFromTransactions(
msgSend := msg.(bank.MsgSend)

sendAmount := msgSend.Amount
if sendAmount.AmountOf("ugnot") <= 0 {
if sendAmount.AmountOf(ugnot.Denom) <= 0 {
io.ErrPrintfln(
"invalid send amount encountered: %s",
msgSend.Amount.String(),
Expand All @@ -248,7 +249,7 @@ func getBalancesFromTransactions(
if from.IsAllLT(sendAmount) || from.IsAllLT(feeAmount) {
// Account cannot cover send amount / fee
// (see message above)
from = std.NewCoins(std.NewCoin("ugnot", 0))
from = std.NewCoins(std.NewCoin(ugnot.Denom, 0))
}

if from.IsAllGT(sendAmount) {
Expand Down
39 changes: 20 additions & 19 deletions gno.land/cmd/gnoland/genesis_balances_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
Expand Down Expand Up @@ -100,16 +101,16 @@ func TestGenesis_Balances_Add(t *testing.T) {
tempGenesis.Name(),
}

amount := std.NewCoins(std.NewCoin("ugnot", 10))
amount := std.NewCoins(std.NewCoin(ugnot.Denom, 10))

for _, dummyKey := range dummyKeys {
args = append(args, "--single")
args = append(
args,
fmt.Sprintf(
"%s=%dugnot",
"%s=%s",
dummyKey.Address().String(),
amount.AmountOf("ugnot"),
ugnot.ValueString(amount.AmountOf(ugnot.Denom)),
),
)
}
Expand Down Expand Up @@ -158,7 +159,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
require.NoError(t, genesis.SaveAs(tempGenesis.Name()))

dummyKeys := getDummyKeys(t, 10)
amount := std.NewCoins(std.NewCoin("ugnot", 10))
amount := std.NewCoins(std.NewCoin(ugnot.Denom, 10))

balances := make([]string, len(dummyKeys))

Expand All @@ -167,9 +168,9 @@ func TestGenesis_Balances_Add(t *testing.T) {

for index, key := range dummyKeys {
balances[index] = fmt.Sprintf(
"%s=%dugnot",
"%s=%s",
key.Address().String(),
amount.AmountOf("ugnot"),
ugnot.ValueString(amount.AmountOf(ugnot.Denom)),
)
}

Expand Down Expand Up @@ -237,9 +238,9 @@ func TestGenesis_Balances_Add(t *testing.T) {

var (
dummyKeys = getDummyKeys(t, 10)
amount = std.NewCoins(std.NewCoin("ugnot", 10))
amountCoins = std.NewCoins(std.NewCoin("ugnot", 10))
gasFee = std.NewCoin("ugnot", 1000000)
amount = std.NewCoins(std.NewCoin(ugnot.Denom, 10))
amountCoins = std.NewCoins(std.NewCoin(ugnot.Denom, 10))
gasFee = std.NewCoin(ugnot.Denom, 1000000)
txs = make([]std.Tx, 0)
)

Expand Down Expand Up @@ -316,7 +317,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
if index == 0 {
// the first address should
// have a balance of 0
checkAmount = std.NewCoins(std.NewCoin("ugnot", 0))
checkAmount = std.NewCoins(std.NewCoin(ugnot.Denom, 0))
}

if dummyKey.Address().String() == balance.Address.String() {
Expand Down Expand Up @@ -347,7 +348,7 @@ func TestGenesis_Balances_Add(t *testing.T) {
Balances: []gnoland.Balance{
{
Address: dummyKeys[0].Address(),
Amount: std.NewCoins(std.NewCoin("ugnot", 100)),
Amount: std.NewCoins(std.NewCoin(ugnot.Denom, 100)),
},
},
}
Expand All @@ -364,16 +365,16 @@ func TestGenesis_Balances_Add(t *testing.T) {
tempGenesis.Name(),
}

amount := std.NewCoins(std.NewCoin("ugnot", 10))
amount := std.NewCoins(std.NewCoin(ugnot.Denom, 10))

for _, dummyKey := range dummyKeys {
args = append(args, "--single")
args = append(
args,
fmt.Sprintf(
"%s=%dugnot",
"%s=%s",
dummyKey.Address().String(),
amount.AmountOf("ugnot"),
ugnot.ValueString(amount.AmountOf(ugnot.Denom)),
),
)
}
Expand Down Expand Up @@ -421,9 +422,9 @@ func TestBalances_GetBalancesFromTransactions(t *testing.T) {

var (
dummyKeys = getDummyKeys(t, 10)
amount = std.NewCoins(std.NewCoin("ugnot", 10))
amountCoins = std.NewCoins(std.NewCoin("ugnot", 10))
gasFee = std.NewCoin("ugnot", 1000000)
amount = std.NewCoins(std.NewCoin(ugnot.Denom, 10))
amountCoins = std.NewCoins(std.NewCoin(ugnot.Denom, 10))
gasFee = std.NewCoin(ugnot.Denom, 1000000)
txs = make([]std.Tx, 0)
)

Expand Down Expand Up @@ -479,7 +480,7 @@ func TestBalances_GetBalancesFromTransactions(t *testing.T) {

var (
dummyKeys = getDummyKeys(t, 10)
amountCoins = std.NewCoins(std.NewCoin("ugnot", 10))
amountCoins = std.NewCoins(std.NewCoin(ugnot.Denom, 10))
gasFee = std.NewCoin("gnos", 1) // invalid fee
txs = make([]std.Tx, 0)
)
Expand Down Expand Up @@ -532,7 +533,7 @@ func TestBalances_GetBalancesFromTransactions(t *testing.T) {
var (
dummyKeys = getDummyKeys(t, 10)
amountCoins = std.NewCoins(std.NewCoin("gnogno", 10)) // invalid send amount
gasFee = std.NewCoin("ugnot", 1)
gasFee = std.NewCoin(ugnot.Denom, 1)
txs = make([]std.Tx, 0)
)

Expand Down
3 changes: 2 additions & 1 deletion gno.land/cmd/gnoland/genesis_balances_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/gnolang/gno/tm2/pkg/testutils"
Expand All @@ -18,7 +19,7 @@ func getDummyBalances(t *testing.T, count int) []gnoland.Balance {
t.Helper()

dummyKeys := getDummyKeys(t, count)
amount := std.NewCoins(std.NewCoin("ugnot", 10))
amount := std.NewCoins(std.NewCoin(ugnot.Denom, 10))

balances := make([]gnoland.Balance, len(dummyKeys))

Expand Down
3 changes: 2 additions & 1 deletion gno.land/cmd/gnoland/genesis_balances_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/std"
Expand Down Expand Up @@ -75,7 +76,7 @@ func TestGenesis_Balances_Remove(t *testing.T) {
Balances: []gnoland.Balance{
{
Address: dummyKey.Address(),
Amount: std.NewCoins(std.NewCoin("ugnot", 100)),
Amount: std.NewCoins(std.NewCoin(ugnot.Denom, 100)),
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion gno.land/cmd/gnoland/genesis_txs_add_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto"
Expand All @@ -16,7 +17,7 @@ var errInvalidPackageDir = errors.New("invalid package directory")

var (
genesisDeployAddress = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
genesisDeployFee = std.NewFee(50000, std.MustParseCoin("1000000ugnot"))
genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
)

// newTxsAddPackagesCmd creates the genesis txs add packages subcommand
Expand Down
Loading
Loading