testapp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Coins1000000uband   = sdk.NewCoins(sdk.NewInt64Coin("uband", 1000000))
	Coins99999999uband  = sdk.NewCoins(sdk.NewInt64Coin("uband", 99999999))
	Coins100000000uband = sdk.NewCoins(sdk.NewInt64Coin("uband", 100000000))
)

nolint

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 CreateTestInput

func CreateTestInput(autoActivate bool) (*bandapp.BandApp, sdk.Context, me.Keeper)

CreateTestInput creates a new test environment for unit tests.

func NewSimApp

func NewSimApp(chainID string, logger log.Logger) *bandapp.BandApp

NewSimApp creates instance of our app using in test.

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    crypto.PrivKey
	PubKey     crypto.PubKey
	Address    sdk.AccAddress
	ValAddress sdk.ValAddress
}

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

var (
	Owner         Account
	Alice         Account
	Bob           Account
	Carol         Account
	Validator1    Account
	Validator2    Account
	Validator3    Account
	DataSources   []types.DataSource
	OracleScripts []types.OracleScript
)

nolint

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