-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get Contracts by Creator Address (#1021)
* add query to query.proto * add ContractsByCreatorPrefix in keys.go * add ContractCreatorThirdIndex to keeper.go * add querier * cli * fix test * linting * add key test * no need to change creator when migrate * add query test * minor * add migrate logic * add more test * register migration * minor * Update x/wasm/client/cli/query.go Co-authored-by: Alexander Peters <[email protected]> * nits * remove IterateAllContract * Update x/wasm/keeper/genesis_test.go Co-authored-by: Alexander Peters <[email protected]> * nit * nit: func name * change key * improve TestIteratorContractByCreator * fix test * use IterateContractInfo in migrate2to3 * minor * move key * improve test case * add pagReq in ContractsByCreator query * ordering query * add migrate test * Make ContractsByCreator plural; formatting and minor updates * Comment why AbsoluteTxPositionLen makes sense * Migrate 1 to 2 * Set module version Co-authored-by: Alexander Peters <[email protected]> Co-authored-by: khanh-notional <[email protected]>
- Loading branch information
1 parent
2abf812
commit 6d67d5b
Showing
17 changed files
with
1,221 additions
and
84 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
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,61 @@ | ||
package keeper | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/CosmWasm/wasmd/x/wasm/types" | ||
) | ||
|
||
func TestMigrate1To2(t *testing.T) { | ||
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) | ||
wasmKeeper := keepers.WasmKeeper | ||
|
||
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) | ||
creator := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len)) | ||
keepers.Faucet.Fund(ctx, creator, deposit...) | ||
example := StoreHackatomExampleContract(t, ctx, keepers) | ||
|
||
initMsg := HackatomExampleInitMsg{ | ||
Verifier: RandomAccountAddress(t), | ||
Beneficiary: RandomAccountAddress(t), | ||
} | ||
initMsgBz, err := json.Marshal(initMsg) | ||
require.NoError(t, err) | ||
|
||
em := sdk.NewEventManager() | ||
|
||
// create with no balance is also legal | ||
gotContractAddr1, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) | ||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) | ||
gotContractAddr2, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) | ||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) | ||
gotContractAddr3, _, err := keepers.ContractKeeper.Instantiate(ctx.WithEventManager(em), example.CodeID, creator, nil, initMsgBz, "demo contract 1", nil) | ||
|
||
info1 := wasmKeeper.GetContractInfo(ctx, gotContractAddr1) | ||
info2 := wasmKeeper.GetContractInfo(ctx, gotContractAddr2) | ||
info3 := wasmKeeper.GetContractInfo(ctx, gotContractAddr3) | ||
|
||
// remove key | ||
ctx.KVStore(wasmKeeper.storeKey).Delete(types.GetContractByCreatorSecondaryIndexKey(creator, info1.Created.Bytes(), gotContractAddr1)) | ||
ctx.KVStore(wasmKeeper.storeKey).Delete(types.GetContractByCreatorSecondaryIndexKey(creator, info2.Created.Bytes(), gotContractAddr2)) | ||
ctx.KVStore(wasmKeeper.storeKey).Delete(types.GetContractByCreatorSecondaryIndexKey(creator, info3.Created.Bytes(), gotContractAddr3)) | ||
|
||
// migrator | ||
migrator := NewMigrator(*wasmKeeper) | ||
migrator.Migrate1to2(ctx) | ||
|
||
// check new store | ||
var allContract []string | ||
wasmKeeper.IterateContractsByCreator(ctx, creator, func(addr sdk.AccAddress) bool { | ||
allContract = append(allContract, addr.String()) | ||
return false | ||
}) | ||
|
||
require.Equal(t, []string{gotContractAddr1.String(), gotContractAddr2.String(), gotContractAddr3.String()}, allContract) | ||
} |
Oops, something went wrong.