testapp

package
v2.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2021 License: GPL-3.0 Imports: 41 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	TestDefaultPrepareGas uint64 = 40000
	TestDefaultExecuteGas uint64 = 300000
)
View Source
const (
	DefaultGenTxGas = 1000000
	SimAppChainID   = "simulation-app"
)

SimAppChainID hardcoded chainID for simulation

Variables

View Source
var (
	Owner         Account
	Treasury      Account
	FeePayer      Account
	Alice         Account
	Bob           Account
	Carol         Account
	Validators    []Account
	DataSources   []types.DataSource
	OracleScripts []types.OracleScript
	OwasmVM       *owasm.Vm
)

nolint

View Source
var (
	EmptyCoins          = sdk.Coins(nil)
	Coins1uband         = sdk.NewCoins(sdk.NewInt64Coin("uband", 1))
	Coins10uband        = sdk.NewCoins(sdk.NewInt64Coin("uband", 10))
	Coins11uband        = sdk.NewCoins(sdk.NewInt64Coin("uband", 11))
	Coins1000000uband   = sdk.NewCoins(sdk.NewInt64Coin("uband", 1000000))
	Coins99999999uband  = sdk.NewCoins(sdk.NewInt64Coin("uband", 99999999))
	Coins100000000uband = sdk.NewCoins(sdk.NewInt64Coin("uband", 100000000))
	BadCoins            = []sdk.Coin{{Denom: "uband", Amount: sdk.NewInt(-1)}}
	Port1               = "port-1"
	Port2               = "port-2"
	Channel1            = "channel-1"
	Channel2            = "channel-2"
)

nolint

View Source
var DefaultConsensusParams = &abci.ConsensusParams{
	Block: &abci.BlockParams{
		MaxBytes: 200000,
		MaxGas:   2000000,
	},
	Evidence: &tmproto.EvidenceParams{
		MaxAgeNumBlocks: 302400,
		MaxAgeDuration:  504 * time.Hour,
	},
	Validator: &tmproto.ValidatorParams{
		PubKeyTypes: []string{
			tmtypes.ABCIPubKeyTypeSecp256k1,
		},
	},
}

DefaultConsensusParams defines the default Tendermint consensus params used in SimApp testing.

View Source
var Wasm1 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t1 (func (param i64 i64 i64 i64)))
	(type $t2 (func (param i64 i64)))
	(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare") (type $t0)
	  (local $l0 i64)
	  i64.const 1
	  i64.const 1
	  i32.const 1024
	  i64.extend_u/i32
	  tee_local $l0
	  i64.const 4
	  call $ask_external_data
	  i64.const 2
	  i64.const 2
	  get_local $l0
	  i64.const 4
	  call $ask_external_data
	  i64.const 3
	  i64.const 3
	  get_local $l0
	  i64.const 4
	  call $ask_external_data)
	(func $execute (export "execute") (type $t0)
	  i32.const 1024
	  i64.extend_u/i32
	  i64.const 4
	  call $set_return_data)
	(table $T0 1 1 anyfunc)
	(memory $memory (export "memory") 17)
	(data (i32.const 1024) "beeb"))
`))

A simple Owasm script with the following specification:

PREPARE:
  CALL ask_external_data with EID 1 DID 1 CALLDATA "beeb"
  CALL ask_external_data with EID 2 DID 2 CALLDATA "beeb"
  CALL ask_external_data with EID 3 DID 3 CALLDATA "beeb"
EXECUTE:
  CALL set_return_date with RETDATE "beeb"
View Source
var Wasm2 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t2 (func (param i64 i64)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare")
		i64.const 1024
		i64.const 4
		call $set_return_data)
	(func $execute (export "execute"))
	(memory $memory (export "memory") 17)
	(data (i32.const 1024) "beeb"))
`))

A bad Owasm script with the following specification:

PREPARE:
  CALL set_return_data with RETDATA "beeb" -- Not allowed during prepare
EXECUTE:
  DO NOTHING
View Source
var Wasm3 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t1 (func (param i64 i64 i64 i64)))
	(type $t2 (func (param i64 i64)))
	(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare") (type $t0))
	(func $execute (export "execute") (type $t0))
	(table $T0 1 1 anyfunc)
	(memory $memory (export "memory") 17)
	(data (i32.const 1024) "beeb"))
`))

A silly oracle script, primarily to test that you must make at least one raw request:

PREPARE:
  DO NOTHING
EXECUTE:
  DO NOTHING
View Source
var Wasm4 []byte

An oracle script for testing complex interactions.

PREPARE:
  Call into the given data source ids with the given calldata.
EXECUTE:
  Assume all validators report, append all reports to the final result.
View Source
var Wasm9 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t1 (func (param i64 i64 i64 i64)))
	(type $t2 (func (param i64 i64)))
	(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare") (type $t0))
	(func $execute (export "execute") (type $t0)
	  i32.const 1024
	  i64.extend_u/i32
	  i64.const 4
	  call $set_return_data
	  i32.const 1024
	  i64.extend_u/i32
	  i64.const 4
	  call $set_return_data)
	(table $T0 1 1 anyfunc)
	(memory $memory (export "memory") 17)
	(data (i32.const 1024) "beeb"))
`))
View Source
var WasmExtra1 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t2 (func (param i64 i64)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare") (type $t0))
	(func $execute (export "execute") (type $t0))
	(memory $memory (export "memory") 17))

`))

An extra Owasm code to test creating or editing oracle scripts.

View Source
var WasmExtra1FileName string
View Source
var WasmExtra2 []byte = wat2wasm([]byte(`
(module
	(type $t0 (func))
	(type $t1 (func (param i64 i64 i64 i64)))
	(type $t2 (func (param i64 i64)))
	(import "env" "ask_external_data" (func $ask_external_data (type $t1)))
	(import "env" "set_return_data" (func $set_return_data (type $t2)))
	(func $prepare (export "prepare") (type $t0))
	(func $execute (export "execute") (type $t0))
	(memory $memory (export "memory") 17))
`))

Another extra Owasm code to test creating or editing oracle scripts.

View Source
var WasmExtra2FileName string

Functions

func CheckBalances

func CheckBalances(
	t *testing.T,
	ctx sdk.Context,
	bankKeeper bankkeeper.WrappedBankKeeper,
	address sdk.AccAddress,
	expected sdk.Coins,
)

func CheckErrorf

func CheckErrorf(t *testing.T, err error, errType error, msg string, a ...interface{})

CheckErrorf checks whether - error type is wrapped inside the given error - error match given message string combined with error type

func MustGetBalances

func MustGetBalances(ctx sdk.Context, bankKeeper bankkeeper.WrappedBankKeeper, address sdk.AccAddress) sdk.Coins

func ParseTime

func ParseTime(t int64) time.Time

ParseTime is a helper function to parse from number to time.Time with UTC locale.

func SignAndDeliver

func SignAndDeliver(
	t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
	chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error)

SignAndDeliver signs and delivers a transaction. No simulation occurs as the ibc testing package causes checkState and deliverState to diverge in block time.

func Wasm56

func Wasm56(time int) []byte

An oracle script to test heavy computation.

PREPARE:
  Loop for `time` times and ask external data with calldata "new beeb".
EXECUTE:
  Loop for `time` times and set return data "new beeb".

func Wasm78

func Wasm78(time int) []byte

An oracle script to test large calldata

PREPARE:
  Ask external data with calldata "b"*time
EXECUTE:
  Return with data "b"*time

Types

type Account

type Account struct {
	PrivKey    cryptotypes.PrivKey
	PubKey     cryptotypes.PubKey
	Address    sdk.AccAddress
	ValAddress sdk.ValAddress
}

Account is a data structure to store key of test account.

type EmptyAppOptions

type EmptyAppOptions struct{}

EmptyAppOptions is a stub implementing AppOptions

func (EmptyAppOptions) Get

func (ao EmptyAppOptions) Get(o string) interface{}

Get implements AppOptions

type GasMeterWrapper

type GasMeterWrapper struct {
	sdk.GasMeter
	GasRecords []GasRecord
}

GasMeterWrapper wrap gas meter for testing purpose

func NewGasMeterWrapper

func NewGasMeterWrapper(meter sdk.GasMeter) *GasMeterWrapper

NewGasMeterWrapper to wrap gas meters for testing purposes

func (*GasMeterWrapper) ConsumeGas

func (m *GasMeterWrapper) ConsumeGas(amount sdk.Gas, descriptor string)

func (*GasMeterWrapper) CountDescriptor

func (m *GasMeterWrapper) CountDescriptor(descriptor string) int

func (*GasMeterWrapper) CountRecord

func (m *GasMeterWrapper) CountRecord(amount sdk.Gas, descriptor string) int

type GasRecord

type GasRecord struct {
	Gas        sdk.Gas
	Descriptor string
}

type TestingApp

type TestingApp struct {
	*bandapp.BandApp
}

func CreateTestInput

func CreateTestInput(autoActivate bool) (*TestingApp, sdk.Context, keeper.Keeper)

CreateTestInput creates a new test environment for unit tests.

func NewTestApp

func NewTestApp(chainID string, logger log.Logger) *TestingApp

NewTestApp creates instance of our app using in test.

func SetupWithGenesisValSet

func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *TestingApp

SetupWithGenesisValSet initializes a new SimApp with a validator set and genesis accounts that also act as delegators. For simplicity, each validator is bonded with a delegation of one consensus engine unit (10^6) in the default token of the simapp from first genesis account. A Nop logger is set in SimApp.

func (*TestingApp) GetBaseApp

func (app *TestingApp) GetBaseApp() *baseapp.BaseApp

func (*TestingApp) GetIBCKeeper

func (app *TestingApp) GetIBCKeeper() *ibckeeper.Keeper

GetIBCKeeper implements the TestingApp interface.

func (*TestingApp) GetScopedIBCKeeper

func (app *TestingApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper

GetScopedIBCKeeper implements the TestingApp interface.

func (*TestingApp) GetStakingKeeper

func (app *TestingApp) GetStakingKeeper() stakingkeeper.Keeper

GetStakingKeeper implements the TestingApp interface.

func (*TestingApp) GetTxConfig

func (app *TestingApp) GetTxConfig() client.TxConfig

GetTxConfig implements the TestingApp interface.

type Wasm4Input

type Wasm4Input struct {
	IDs      []int64
	Calldata string
}

type Wasm4Output

type Wasm4Output struct {
	Ret string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL