* Add grant system tests * Add unpermissioned chain test case * Fix tests * Update cli and fix feedbacks * Revisit CLI and system tests (#1627) * Restructure CLI; fix system test * Review feedback --------- Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tidwall/gjson"
|
|
"github.com/tidwall/sjson"
|
|
)
|
|
|
|
// SetConsensusMaxGas max gas that can be consumed in a block
|
|
func SetConsensusMaxGas(t *testing.T, max int) GenesisMutator {
|
|
return func(genesis []byte) []byte {
|
|
t.Helper()
|
|
state, err := sjson.SetRawBytes(genesis, "consensus_params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, max)))
|
|
require.NoError(t, err)
|
|
return state
|
|
}
|
|
}
|
|
|
|
// GetGenesisBalance return the balance amount for an address from the given genesis json
|
|
func GetGenesisBalance(rawGenesis []byte, addr string) sdk.Coins {
|
|
var r []sdk.Coin
|
|
balances := gjson.GetBytes(rawGenesis, fmt.Sprintf(`app_state.bank.balances.#[address==%q]#.coins`, addr)).Array()
|
|
for _, coins := range balances {
|
|
for _, coin := range coins.Array() {
|
|
r = append(r, sdk.NewCoin(coin.Get("denom").String(), sdk.NewInt(coin.Get("amount").Int())))
|
|
}
|
|
}
|
|
return r
|
|
}
|
|
|
|
// SetCodeUploadPermission sets the code upload permissions
|
|
func SetCodeUploadPermission(t *testing.T, permission string, addresses ...string) GenesisMutator {
|
|
return func(genesis []byte) []byte {
|
|
t.Helper()
|
|
state, err := sjson.Set(string(genesis), "app_state.wasm.params.code_upload_access.permission", permission)
|
|
require.NoError(t, err)
|
|
state, err = sjson.Set(state, "app_state.wasm.params.code_upload_access.addresses", addresses)
|
|
require.NoError(t, err)
|
|
return []byte(state)
|
|
}
|
|
}
|