generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
487 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package predicate | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
dbm "github.com/cosmos/cosmos-db" | ||
"github.com/golang/mock/gomock" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
|
||
"cosmossdk.io/log" | ||
"cosmossdk.io/store" | ||
"cosmossdk.io/store/metrics" | ||
"cosmossdk.io/x/evidence" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
|
||
"github.com/axone-protocol/axoned/v10/x/logic/testutil" | ||
"github.com/axone-protocol/axoned/v10/x/logic/types" | ||
) | ||
|
||
func TestAccounts(t *testing.T) { | ||
Convey("Given a mocked context and authQueryService", t, func() { | ||
ctrl := gomock.NewController(t) | ||
sdk.GetConfig().SetBech32PrefixForAccount("axone", "axonepub") | ||
addresses := []string{ | ||
"axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa", | ||
"axone1wze8mn5nsgl9qrgazq6a92fvh7m5e6ps372aep", | ||
} | ||
authQueryServiceKeeper := testutil.NewMockAuthQueryService(ctrl) | ||
testutil.MockAuthQueryServiceWithAddresses(authQueryServiceKeeper, addresses) | ||
encCfg := moduletestutil.MakeTestEncodingConfig(evidence.AppModuleBasic{}) | ||
|
||
db := dbm.NewMemDB() | ||
stateStore := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) | ||
|
||
Convey("Given a mocked context", func() { | ||
ctx := sdk. | ||
NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()). | ||
WithValue(types.AuthQueryServiceContextKey, authQueryServiceKeeper). | ||
WithValue(types.InterfaceRegistryContextKey, encCfg.InterfaceRegistry) | ||
|
||
Convey("When Accounts is called", func() { | ||
next := Accounts(ctx, authQueryServiceKeeper) | ||
|
||
Convey("Then next() returns all the addresses", func() { | ||
for i := 0; i < 2; i++ { | ||
result, ok := next() | ||
So(ok, ShouldBeTrue) | ||
So(result.A.GetAddress().String(), ShouldEqual, addresses[i]) | ||
So(result.B, ShouldBeNil) | ||
} | ||
for i := 0; i < 2; i++ { | ||
result, ok := next() | ||
So(ok, ShouldBeFalse) | ||
So(result.A, ShouldBeNil) | ||
So(result.B, ShouldBeNil) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
Convey("Given a badly mocked context", func() { | ||
interfaceRegistry := testutil.NewMockInterfaceRegistry(ctrl) | ||
|
||
ctx := sdk. | ||
NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()). | ||
WithValue(types.AuthQueryServiceContextKey, authQueryServiceKeeper). | ||
WithValue(types.InterfaceRegistryContextKey, interfaceRegistry) | ||
|
||
interfaceRegistry. | ||
EXPECT(). | ||
UnpackAny(gomock.Any(), gomock.Any()). | ||
AnyTimes(). | ||
Return(errors.New("I was told not to unpack anything")) | ||
|
||
Convey("When Accounts is called", func() { | ||
next := Accounts(ctx, authQueryServiceKeeper) | ||
|
||
Convey("Then next() returns an error", func() { | ||
result, ok := next() | ||
So(ok, ShouldBeTrue) | ||
So(result.A, ShouldBeNil) | ||
So(result.B, ShouldBeError, errors.New("I was told not to unpack anything")) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.