* More keeper tests x/wasm/keeper tests are extended to test various input validation. Keeper input is validated before passing to the keeper method when used within wasmd application. We cannot ensure such validation when this keeper is used outside of wasmd application. To keep it safe, fully validate keeper methods input. hackatom.wasm is loaded into memory during initialization to avoid reading file in each test separately. Once migrated to go 1.16, embed package should be used instead. Run goimport on certain files. Some comments fixed or removed. * ensure that creator address is not nil
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package keeper
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
wasmvm "github.com/CosmWasm/wasmvm"
|
|
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
const (
|
|
// DefaultGasCostHumanAddress is how moch SDK gas we charge to convert to a human address format
|
|
DefaultGasCostHumanAddress = 5
|
|
// DefaultGasCostCanonicalAddress is how moch SDK gas we charge to convert to a canonical address format
|
|
DefaultGasCostCanonicalAddress = 4
|
|
|
|
// DefaultDeserializationCostPerByte The formular should be `len(data) * deserializationCostPerByte`
|
|
DefaultDeserializationCostPerByte = 1
|
|
)
|
|
|
|
var (
|
|
costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier
|
|
costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier
|
|
costJsonDeserialization = wasmvmtypes.UFraction{
|
|
Numerator: DefaultDeserializationCostPerByte * DefaultGasMultiplier,
|
|
Denominator: 1,
|
|
}
|
|
)
|
|
|
|
func humanAddress(canon []byte) (string, uint64, error) {
|
|
if len(canon) != sdk.AddrLen {
|
|
return "", costHumanize, fmt.Errorf("Expected %d byte address", sdk.AddrLen)
|
|
}
|
|
return sdk.AccAddress(canon).String(), costHumanize, nil
|
|
}
|
|
|
|
func canonicalAddress(human string) ([]byte, uint64, error) {
|
|
bz, err := sdk.AccAddressFromBech32(human)
|
|
return bz, costCanonical, err
|
|
}
|
|
|
|
var cosmwasmAPI = wasmvm.GoAPI{
|
|
HumanAddress: humanAddress,
|
|
CanonicalAddress: canonicalAddress,
|
|
}
|