diff --git a/x/mailbox/keeper/genesis.go b/x/mailbox/keeper/genesis.go index 65c081a..1707100 100644 --- a/x/mailbox/keeper/genesis.go +++ b/x/mailbox/keeper/genesis.go @@ -14,9 +14,10 @@ import ( func (k *Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) error { k.StoreTree(ctx, gs.Tree) + store := ctx.KVStore(k.storeKey) // Delivered Messages. for _, msgDelivered := range gs.DeliveredMessages { - k.Delivered[msgDelivered.Id] = true + store.Set(types.MailboxDeliveredKey(msgDelivered.Id), []byte{1}) } // Domain k.SetDomain(ctx, gs.Domain) diff --git a/x/mailbox/keeper/genesis_test.go b/x/mailbox/keeper/genesis_test.go index 0231b26..b7b7f74 100644 --- a/x/mailbox/keeper/genesis_test.go +++ b/x/mailbox/keeper/genesis_test.go @@ -49,7 +49,20 @@ func (suite *KeeperTestSuite) TestGenesis() { // Comparing the two states to make sure they are the same tree := suite.keeper.GetImtTree(suite.ctx) suite.Require().Equal(8, countKeeperPopulatedSlices(tree.Branch)) - suite.Require().Equal(128, len(suite.keeper.Delivered)) + + // Verify each delivered message is found + for i := 0; i < 128; i++ { + id, err := hexutil.Decode(idMap[i]) + suite.Require().NoError(err) + req := types.QueryMsgDeliveredRequest{ + MessageId: id, + } + resp, err := suite.queryClient.MsgDelivered(suite.ctx, &req) + suite.Require().NoError(err) + suite.Require().True(resp.Delivered, "Message delivered was not found") + } + + // Check that the branches match isEqual := reflect.DeepEqual(gs.Tree.Branch, tree.Branch[:]) suite.Require().True(isEqual, "Imported state is not the same as exported state") } diff --git a/x/mailbox/keeper/keeper.go b/x/mailbox/keeper/keeper.go index ebac20b..91cdba0 100644 --- a/x/mailbox/keeper/keeper.go +++ b/x/mailbox/keeper/keeper.go @@ -40,8 +40,6 @@ type Keeper struct { authority string mailboxAddr sdk.AccAddress version byte - - Delivered map[string]bool } type ReadOnlyMailboxKeeper interface { @@ -66,7 +64,6 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, cwKeeper *cosmwas mailboxAddr: authtypes.NewModuleAddress(types.ModuleName), version: 0, pcwKeeper: cosmwasm.NewDefaultPermissionKeeper(cwKeeper), - Delivered: map[string]bool{}, } } diff --git a/x/mailbox/keeper/msg_server.go b/x/mailbox/keeper/msg_server.go index 4afe0c8..9d799ca 100644 --- a/x/mailbox/keeper/msg_server.go +++ b/x/mailbox/keeper/msg_server.go @@ -194,7 +194,6 @@ func (k Keeper) Process(goCtx context.Context, msg *types.MsgProcess) (*types.Ms // Store that the message was delivered store := ctx.KVStore(k.storeKey) store.Set(types.MailboxDeliveredKey(id), []byte{1}) - k.Delivered[id] = true // Emit the events ctx.EventManager().EmitEvents(sdk.Events{