Minor integration support
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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(),
|
||||
|
||||
@@ -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...)
|
||||
@@ -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...)
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user