Skip to content

Commit

Permalink
cleaned up interfaces and addressed empty genesis state
Browse files Browse the repository at this point in the history
  • Loading branch information
piux2 committed Jan 30, 2025
1 parent 625fa5b commit 842c80d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci

for _, addr := range state.Auth.Params.UnrestrictedAddrs {
acc := cfg.acctKpr.GetAccount(ctx, addr)
accr := acc.(AccountRestricter)
accr := acc.(*GnoAccount)
accr.SetUnrestricted()
cfg.acctKpr.SetAccount(ctx, acc)
}
Expand Down
8 changes: 2 additions & 6 deletions gno.land/pkg/gnoland/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (bs BitSet) String() string {
return fmt.Sprintf("%016b", bs) // Show all 16 bits

Check warning on line 40 in gno.land/pkg/gnoland/types.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/types.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}

var _ std.AccountRestricter = &GnoAccount{}

type GnoAccount struct {
std.BaseAccount
Attributes BitSet `json:"attributes" yaml:"attributes"`
Expand Down Expand Up @@ -104,12 +106,6 @@ func ProtoGnoAccount() std.Account {
return &GnoAccount{}
}

type AccountRestricter interface {
IsRestricted() bool
SetUnrestricted()
SetRestricted()
}

type GnoGenesisState struct {
Balances []Balance `json:"balances"`
Txs []TxWithMetadata `json:"txs"`
Expand Down
12 changes: 6 additions & 6 deletions gno.land/pkg/gnoland/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ func TestGnoAccountRestriction(t *testing.T) {
toAccount := acckpr.NewAccountWithAddress(ctx, toAddress)

// Unrestrict Account
fromAccount.(AccountRestricter).SetUnrestricted()
assert.False(t, fromAccount.(AccountRestricter).IsRestricted())
fromAccount.(*GnoAccount).SetUnrestricted()
assert.False(t, fromAccount.(*GnoAccount).IsRestricted())

// Persisted unrestricted state
acckpr.SetAccount(ctx, fromAccount)
fromAccount = acckpr.GetAccount(ctx, fromAddress)
assert.False(t, fromAccount.(AccountRestricter).IsRestricted())
assert.False(t, fromAccount.(*GnoAccount).IsRestricted())

// Restrict Account
fromAccount.(AccountRestricter).SetRestricted()
assert.True(t, fromAccount.(AccountRestricter).IsRestricted())
fromAccount.(*GnoAccount).SetRestricted()
assert.True(t, fromAccount.(*GnoAccount).IsRestricted())

// Persisted restricted state
acckpr.SetAccount(ctx, fromAccount)
fromAccount = acckpr.GetAccount(ctx, fromAddress)
assert.True(t, fromAccount.(AccountRestricter).IsRestricted())
assert.True(t, fromAccount.(*GnoAccount).IsRestricted())

// Send Unrestricted
fromAccount.SetCoins(std.NewCoins(std.NewCoin("foocoin", 10)))
Expand Down
3 changes: 3 additions & 0 deletions gno.land/pkg/sdk/vm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func ValidateGenesis(data GenesisState) error {
// InitGenesis - Init store state from genesis data
func (vm *VMKeeper) InitGenesis(ctx sdk.Context, data GenesisState) {
if amino.DeepEqual(data, GenesisState{}) {
if err := vm.SetParams(ctx, DefaultParams()); err != nil {
panic(err)

Check warning on line 33 in gno.land/pkg/sdk/vm/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/genesis.go#L33

Added line #L33 was not covered by tests
}
return
}

Expand Down
13 changes: 4 additions & 9 deletions tm2/pkg/std/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
//
// Many complex conditions can be used in the concrete struct which implements Account.
type Account interface {
AccountRestricter
GetAddress() crypto.Address
SetAddress(crypto.Address) error // errors if already set.

Expand All @@ -39,6 +38,10 @@ type Account interface {
String() string
}

type AccountRestricter interface {
IsRestricted() bool
}

//----------------------------------------
// BaseAccount

Expand Down Expand Up @@ -152,11 +155,3 @@ func (acc *BaseAccount) SetSequence(seq uint64) error {
acc.Sequence = seq
return nil
}

type AccountRestricter interface {
IsRestricted() bool
}

func (acc *BaseAccount) IsRestricted() bool {
return false
}

0 comments on commit 842c80d

Please sign in to comment.