Skip to content

Commit

Permalink
Merge pull request #740 from CosmWasm/minor_integration_support
Browse files Browse the repository at this point in the history
Minor integration support
  • Loading branch information
ethanfrey authored Jan 30, 2022
2 parents 891b406 + 26c3b67 commit 4944454
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
14 changes: 8 additions & 6 deletions x/wasm/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request
}
coins := bankKeeper.GetAllBalances(ctx, addr)
res := wasmvmtypes.AllBalancesResponse{
Amount: convertSdkCoinsToWasmCoins(coins),
Amount: ConvertSdkCoinsToWasmCoins(coins),
}
return json.Marshal(res)
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations [
result[i] = wasmvmtypes.Delegation{
Delegator: delAddr.String(),
Validator: valAddr.String(),
Amount: convertSdkCoinToWasmCoin(amount),
Amount: ConvertSdkCoinToWasmCoin(amount),
}
}
return result, nil
Expand All @@ -410,7 +410,7 @@ func sdkToFullDelegation(ctx sdk.Context, keeper types.StakingKeeper, distKeeper
bondDenom := keeper.BondDenom(ctx)
amount := sdk.NewCoin(bondDenom, val.TokensFromShares(delegation.Shares).TruncateInt())

delegationCoins := convertSdkCoinToWasmCoin(amount)
delegationCoins := ConvertSdkCoinToWasmCoin(amount)

// FIXME: this is very rough but better than nothing...
// https://github.com/CosmWasm/wasmd/issues/282
Expand Down Expand Up @@ -507,15 +507,17 @@ func WasmQuerier(k wasmQueryKeeper) func(ctx sdk.Context, request *wasmvmtypes.W
}
}

func convertSdkCoinsToWasmCoins(coins []sdk.Coin) wasmvmtypes.Coins {
// ConvertSdkCoinsToWasmCoins covert sdk type to wasmvm coins type
func ConvertSdkCoinsToWasmCoins(coins []sdk.Coin) wasmvmtypes.Coins {
converted := make(wasmvmtypes.Coins, len(coins))
for i, c := range coins {
converted[i] = convertSdkCoinToWasmCoin(c)
converted[i] = ConvertSdkCoinToWasmCoin(c)
}
return converted
}

func convertSdkCoinToWasmCoin(coin sdk.Coin) wasmvmtypes.Coin {
// ConvertSdkCoinToWasmCoin covert sdk type to wasmvm coin type
func ConvertSdkCoinToWasmCoin(coin sdk.Coin) wasmvmtypes.Coin {
return wasmvmtypes.Coin{
Denom: coin.Denom,
Amount: coin.Amount.String(),
Expand Down
21 changes: 11 additions & 10 deletions x/wasm/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ var TestingStakeParams = stakingtypes.Params{
}

type TestFaucet struct {
t testing.TB
bankKeeper bankkeeper.Keeper
sender sdk.AccAddress
balance sdk.Coins
t testing.TB
bankKeeper bankkeeper.Keeper
sender sdk.AccAddress
balance sdk.Coins
minterModuleName string
}

func NewTestFaucet(t testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, initialAmount ...sdk.Coin) *TestFaucet {
func NewTestFaucet(t testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper, minterModuleName string, initialAmount ...sdk.Coin) *TestFaucet {
require.NotEmpty(t, initialAmount)
r := &TestFaucet{t: t, bankKeeper: bankKeeper}
r := &TestFaucet{t: t, bankKeeper: bankKeeper, minterModuleName: minterModuleName}
_, _, addr := keyPubAddr()
r.sender = addr
r.Mint(ctx, addr, initialAmount...)
Expand All @@ -140,9 +141,9 @@ func NewTestFaucet(t testing.TB, ctx sdk.Context, bankKeeper bankkeeper.Keeper,
func (f *TestFaucet) Mint(parentCtx sdk.Context, addr sdk.AccAddress, amounts ...sdk.Coin) {
require.NotEmpty(f.t, amounts)
ctx := parentCtx.WithEventManager(sdk.NewEventManager()) // discard all faucet related events
err := f.bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
err := f.bankKeeper.MintCoins(ctx, f.minterModuleName, amounts)
require.NoError(f.t, err)
err = f.bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
err = f.bankKeeper.SendCoinsFromModuleToAccount(ctx, f.minterModuleName, addr, amounts)
require.NoError(f.t, err)
f.balance = f.balance.Add(amounts...)
}
Expand Down Expand Up @@ -323,7 +324,7 @@ func createTestInput(
nil,
)

faucet := NewTestFaucet(t, ctx, bankKeeper, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000)))
faucet := NewTestFaucet(t, ctx, bankKeeper, minttypes.ModuleName, sdk.NewCoin("stake", sdk.NewInt(100_000_000_000)))

// set some funds ot pay out validatores, based on code from:
// https://github.com/cosmos/cosmos-sdk/blob/fea231556aee4d549d7551a6190389c4328194eb/x/distribution/keeper/keeper_test.go#L50-L57
Expand Down Expand Up @@ -692,7 +693,7 @@ func (m BurnerExampleInitMsg) GetBytes(t testing.TB) []byte {
func fundAccounts(t testing.TB, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, addr sdk.AccAddress, coins sdk.Coins) {
acc := am.NewAccountWithAddress(ctx, addr)
am.SetAccount(ctx, acc)
NewTestFaucet(t, ctx, bank, coins...).Fund(ctx, addr, coins...)
NewTestFaucet(t, ctx, bank, minttypes.ModuleName, coins...).Fund(ctx, addr, coins...)
}

var keyCounter uint64
Expand Down

0 comments on commit 4944454

Please sign in to comment.