testapp

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: GPL-3.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestDefaultPrepareGas uint64 = 40000
	TestDefaultExecuteGas uint64 = 300000
)
View Source
const (
	DefaultGenTxGas = 1000000
)

Variables

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

nolint

View Source
var (
	EmptyCoins               = sdk.Coins(nil)
	Coins1loki               = sdk.NewCoins(sdk.NewInt64Coin("loki", 1))
	Coins10loki              = sdk.NewCoins(sdk.NewInt64Coin("loki", 10))
	Coins11loki              = sdk.NewCoins(sdk.NewInt64Coin("loki", 11))
	Coins1000000minigeo      = sdk.NewCoins(sdk.NewInt64Coin("minigeo", 1000000))
	Coin100000000minigeo     = sdk.NewInt64Coin("minigeo", 100000000)
	Coins1000000loki         = sdk.NewCoins(sdk.NewInt64Coin("loki", 1000000))
	Coin100000000loki        = sdk.NewInt64Coin("loki", 100000000)
	Coins99999999loki        = sdk.NewCoins(sdk.NewInt64Coin("loki", 99999999))
	Coins100000000loki       = sdk.NewCoins(sdk.NewInt64Coin("loki", 100000000))
	Coins10000000000loki     = sdk.NewCoins(sdk.NewInt64Coin("loki", 10000000000))
	BadCoins                 = []sdk.Coin{{Denom: "loki", Amount: math.NewInt(-1)}}
	Port1                    = "port-1"
	Port2                    = "port-2"
	Channel1                 = "channel-1"
	Channel2                 = "channel-2"
	DefaultCommunityPool     = sdk.NewCoins(Coin100000000minigeo, Coin100000000loki)
	DefaultDataProvidersPool = sdk.NewCoins(Coin100000000loki)
)

nolint

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

DefaultConsensusParams defines the default Tendermint consensus params used in TestingApp.

View Source
var Wasm1 []byte = wat2wasm(`
(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_i32_u
	  local.tee $l0
	  i64.const 4
	  call $ask_external_data
	  i64.const 2
	  i64.const 2
	  local.get $l0
	  i64.const 4
	  call $ask_external_data
	  i64.const 3
	  i64.const 3
	  local.get $l0
	  i64.const 4
	  call $ask_external_data)
	(func $execute (export "execute") (type $t0)
	(local $idx i32)
              (local.set $idx (i32.const 0))
              (block
                  (loop
                    (local.set $idx (local.get $idx) (i32.const 1) (i32.add) )
                    (br_if 0 (i32.lt_u (local.get $idx) (i32.const 100)))
                  )
                )
	  i32.const 1024
	  i64.extend_i32_u
	  i64.const 4
	  call $set_return_data)
	(table $T0 1 1 funcref)
	(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(`
(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(`
(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 funcref)
	(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(`
(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_i32_u
	  i64.const 4
	  call $set_return_data
	  i32.const 1024
	  i64.extend_i32_u
	  i64.const 4
	  call $set_return_data)
	(table $T0 1 1 funcref)
	(memory $memory (export "memory") 17)
	(data (i32.const 1024) "beeb"))
`)
View Source
var WasmExtra1 []byte = wat2wasm(`
(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(`
(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 context.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 context.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 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 {
	storetypes.GasMeter
	GasRecords []GasRecord
}

GasMeterWrapper wrap gas meter for testing purpose

func NewGasMeterWrapper

func NewGasMeterWrapper(meter storetypes.GasMeter) *GasMeterWrapper

NewGasMeterWrapper to wrap gas meters for testing purposes

func (*GasMeterWrapper) ConsumeGas

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

func (*GasMeterWrapper) CountDescriptor

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

func (*GasMeterWrapper) CountRecord

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

type GasRecord

type GasRecord struct {
	Gas        storetypes.Gas
	Descriptor string
}

type TestingApp

type TestingApp struct {
	*odinapp.OdinApp
}

func CreateTestInput

func CreateTestInput(params ...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 SetupWithEmptyStore

func SetupWithEmptyStore() *TestingApp

SetupWithEmptyStore setup a TestingApp instance with empty DB

func SetupWithGenesisValSet

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

SetupWithGenesisValSet initializes a new TestingApp 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 OdinChain from first genesis account. A Nop logger is set in TestingApp.

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 Validator added in v0.8.0

type Validator struct {
	PrivKey    crypto.PrivKey
	PubKey     crypto.PubKey
	Address    sdk.AccAddress
	ValAddress sdk.ValAddress
}

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