wasmsolo

package
v0.6.1-alpha.6-prerelease Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SoloDebug        = false
	SoloHostTracing  = false
	SoloStackTracing = false
)
View Source
const (
	MinGasFee         = 100
	L1FundsAgent      = utxodb.FundsFromFaucetAmount - 10*isc.Million - MinGasFee
	L2FundsAgent      = 10 * isc.Million
	L2FundsContract   = 10 * isc.Million
	L2FundsCreator    = 20 * isc.Million
	L2FundsOriginator = 30 * isc.Million
)

Variables

View Source
var (
	// GoWasm / RsWasm / TsWasm are used to specify the Wasm language mode,
	// By default, SoloContext will try to run the Go SC code directly (no Wasm)
	// The 3 flags can be used to cause Wasm code to be loaded and run instead.
	// They are checked in sequence and the first one set determines the Wasm language used.
	GoWasm = flag.Bool("gowasm", false, "use Go Wasm smart contract code")
	RsWasm = flag.Bool("rswasm", false, "use Rust Wasm smart contract code")
	TsWasm = flag.Bool("tswasm", false, "use TypeScript Wasm smart contract code")

	// UseWasmEdge flag is kept here in case we decide to use WasmEdge again. Some tests
	// refer to this flag, so we keep it here instead of having to comment out a bunch
	// of code. To actually enable WasmEdge you need to uncomment the relevant lines in
	// NewSoloContextForChain(), and remove the go:build directives from wasmedge.go, so
	// that the linker can actually pull in the WasmEdge runtime.
	UseWasmEdge = flag.Bool("wasmedge", false, "use WasmEdge instead of WasmTime")
)

Functions

func StartChain

func StartChain(t solo.TestContext, chainName string, env ...*solo.Solo) *solo.Chain

StartChain starts a new chain named chainName.

Types

type SoloAgent

type SoloAgent struct {
	Env  *solo.Solo
	ID   string
	Name string
	Pair *cryptolib.KeyPair
	// contains filtered or unexported fields
}

func NewSoloAgent

func NewSoloAgent(env *solo.Solo, name string) *SoloAgent

func (*SoloAgent) AgentID added in v0.3.0

func (a *SoloAgent) AgentID() isc.AgentID

func (*SoloAgent) Balance

func (a *SoloAgent) Balance(nativeTokenID ...wasmtypes.ScTokenID) uint64

The optional nativeTokenID parameter can be used to retrieve the balance for the specific token. When nativeTokenID is omitted, the base tokens balance is assumed.

func (*SoloAgent) ScAgentID

func (a *SoloAgent) ScAgentID() wasmtypes.ScAgentID

type SoloBalances added in v0.3.0

type SoloBalances struct {
	Account uint64

	Chain uint64

	Originator uint64
	// contains filtered or unexported fields
}

func NewSoloBalances added in v0.3.0

func NewSoloBalances(ctx *SoloContext, agents ...*SoloAgent) *SoloBalances

NewSoloBalances takes a snapshot of all balances necessary to track token movements easily. It will track L2 Originator, Chain, snd SC Account balances Additional agents can be specified as extra accounts This is typically called from SoloContext.Balances() before a call to the SC. After the call, update the balances with the expected token movements and then call SoloBalances.VerifyBalances() to see if they match the actual balances.

func (*SoloBalances) Add added in v0.3.0

func (bal *SoloBalances) Add(agent *SoloAgent, balance uint64)

func (*SoloBalances) DumpBalances added in v1.0.3

func (bal *SoloBalances) DumpBalances()

DumpBalances prints all known accounts, both L2 and L1, in debug mode. It uses the L2 ledger to enumerate the known accounts.

func (*SoloBalances) VerifyBalances added in v0.3.0

func (bal *SoloBalances) VerifyBalances(t solo.TestContext)

type SoloClientService added in v0.3.0

type SoloClientService struct {
	// contains filtered or unexported fields
}

func NewSoloClientService added in v0.3.0

func NewSoloClientService(ctx *SoloContext, chainID string, extra ...bool) *SoloClientService

NewSoloClientService creates a new SoloClientService Normally we reset the subscribers, assuming a new test. To prevent this when testing with multiple SoloClients, use the optional extra flag to indicate the extra clients.

func (*SoloClientService) CallViewByHname added in v0.3.0

func (svc *SoloClientService) CallViewByHname(hContract, hFunction wasmtypes.ScHname, args []byte) ([]byte, error)

func (*SoloClientService) CurrentChainID added in v1.0.3

func (svc *SoloClientService) CurrentChainID() wasmtypes.ScChainID

func (*SoloClientService) Event added in v0.3.0

func (svc *SoloClientService) Event(msg string)

func (*SoloClientService) PostRequest added in v0.3.0

func (svc *SoloClientService) PostRequest(chainID wasmtypes.ScChainID, hContract, hFunction wasmtypes.ScHname, args []byte, allowance *wasmlib.ScAssets, keyPair *cryptolib.KeyPair) (reqID wasmtypes.ScRequestID, err error)

func (*SoloClientService) SubscribeEvents added in v0.3.0

func (svc *SoloClientService) SubscribeEvents(eventHandler *wasmclient.WasmClientEvents) error

func (*SoloClientService) UnsubscribeEvents added in v1.0.3

func (svc *SoloClientService) UnsubscribeEvents(eventsID uint32)

func (*SoloClientService) WaitUntilRequestProcessed added in v0.3.0

func (svc *SoloClientService) WaitUntilRequestProcessed(reqID wasmtypes.ScRequestID, timeout time.Duration) error

type SoloContext

type SoloContext struct {
	Chain *solo.Chain
	Cvt   wasmhost.WasmConvertor

	StorageDeposit uint64
	Err            error
	Gas            uint64
	GasFee         uint64
	Hprog          hashing.HashValue

	IsWasm bool

	Tx *iotago.Transaction
	// contains filtered or unexported fields
}

func NewSoloContext

func NewSoloContext(t solo.TestContext, scName string, onLoad wasmhost.ScOnloadFunc, init ...*wasmlib.ScInitFunc) *SoloContext

NewSoloContext can be used to create a SoloContext associated with a smart contract with minimal information and will verify successful creation before returning ctx. It will start a default chain "chain1" before initializing the smart contract. It takes the scName and onLoad() function associated with the contract. Optionally, an init.Func that has been initialized with the parameters to pass to the contract's init() function can be specified. Unless you want to use a different chain than the default "chain1" this will be your function of choice to set up a smart contract for your tests

func NewSoloContextForChain

func NewSoloContextForChain(t solo.TestContext, chain *solo.Chain, creator *SoloAgent, scName string,
	onLoad wasmhost.ScOnloadFunc, init ...*wasmlib.ScInitFunc,
) *SoloContext

NewSoloContextForChain can be used to create a SoloContext associated with a smart contract on a particular chain. When chain is nil the function will start a default chain "chain1" before initializing the smart contract. When creator is nil the creator will be the chain originator It takes the scName and onLoad() function associated with the contract. Optionally, an init.Func that has been initialized with the parameters to pass to the contract's init() function can be specified. You can check for any error that occurred by checking the ctx.Err member.

func NewSoloContextForNative

func NewSoloContextForNative(t solo.TestContext, chain *solo.Chain, creator *SoloAgent, scName string, onLoad wasmhost.ScOnloadFunc,
	proc *coreutil.ContractProcessor, init ...*wasmlib.ScInitFunc,
) *SoloContext

NewSoloContextForNative can be used to create a SoloContext associated with a native smart contract on a particular chain. When chain is nil the function will start a default chain "chain1" before deploying and initializing the smart contract. When creator is nil the creator will be the chain originator It takes the scName, onLoad() function, and processor associated with the contract. Optionally, an init.Func that has been initialized with the parameters to pass to the contract's init() function can be specified. You can check for any error that occurred by checking the ctx.Err member.

func (*SoloContext) Account

func (ctx *SoloContext) Account() *SoloAgent

Account returns a SoloAgent for the smart contract associated with ctx

func (*SoloContext) AccountID

func (ctx *SoloContext) AccountID() wasmtypes.ScAgentID

func (*SoloContext) AdvanceClockBy

func (ctx *SoloContext) AdvanceClockBy(step time.Duration)

AdvanceClockBy is used to forward the internal clock by the provided step duration.

func (*SoloContext) Balance

func (ctx *SoloContext) Balance(agent *SoloAgent, nativeTokenID ...wasmtypes.ScTokenID) uint64

Balance returns the account balance of the specified agent on the chain associated with ctx. The optional nativeTokenID parameter can be used to retrieve the balance for the specific token. When nativeTokenID is omitted, the base tokens balance is assumed.

func (*SoloContext) Balances added in v0.3.0

func (ctx *SoloContext) Balances(agents ...*SoloAgent) *SoloBalances

Balances prints all known accounts, both L2 and L1. It uses the L2 ledger to enumerate the known accounts. Any newly created SoloAgents can be specified as extra accounts

func (*SoloContext) ChainAccount added in v0.3.0

func (ctx *SoloContext) ChainAccount() *SoloAgent

ChainAccount returns a SoloAgent for the chain associated with ctx

func (*SoloContext) ChainOwnerID

func (ctx *SoloContext) ChainOwnerID() wasmtypes.ScAgentID

func (*SoloContext) ContractExists

func (ctx *SoloContext) ContractExists(scName string) error

ContractExists checks to see if the contract named scName exists in the chain associated with ctx.

func (*SoloContext) Creator

func (ctx *SoloContext) Creator() *SoloAgent

Creator returns a SoloAgent representing the contract creator

func (*SoloContext) CurrentChainID added in v0.3.0

func (ctx *SoloContext) CurrentChainID() wasmtypes.ScChainID

func (*SoloContext) EnqueueRequest

func (ctx *SoloContext) EnqueueRequest()

func (*SoloContext) FnCall added in v1.0.3

func (ctx *SoloContext) FnCall(req *wasmrequests.CallRequest) []byte

func (*SoloContext) FnChainID added in v1.0.3

func (ctx *SoloContext) FnChainID() wasmtypes.ScChainID

func (*SoloContext) FnPost added in v1.0.3

func (ctx *SoloContext) FnPost(req *wasmrequests.PostRequest) []byte

func (*SoloContext) Host

func (ctx *SoloContext) Host() wasmlib.ScHost

func (*SoloContext) InitFuncCallContext

func (ctx *SoloContext) InitFuncCallContext()

InitFuncCallContext is a function that is required to use SoloContext as an ScFuncCallContext

func (*SoloContext) InitViewCallContext

func (ctx *SoloContext) InitViewCallContext(hContract wasmtypes.ScHname) wasmtypes.ScHname

InitViewCallContext is a function that is required to use SoloContext as an ScViewCallContext

func (*SoloContext) MintNFT added in v0.3.0

func (ctx *SoloContext) MintNFT(agent *SoloAgent, metadata []byte) wasmtypes.ScNftID

MintNFT tells SoloContext to mint a new NFT issued/owned by the specified agent note that SoloContext will cache the NFT data to be able to use it in Post()s that go through the *SAME* SoloContext

func (*SoloContext) NFTs added in v0.3.0

func (ctx *SoloContext) NFTs(agent *SoloAgent) []wasmtypes.ScNftID

NFTs returns the list of NFTs in the account of the specified agent on the chain associated with ctx.

func (*SoloContext) NewSoloAgent

func (ctx *SoloContext) NewSoloAgent(name string) *SoloAgent

NewSoloAgent creates a new SoloAgent with utxodb.FundsFromFaucetAmount (1 Gi) tokens in its address and pre-deposits 10Mi into the corresponding chain account

func (*SoloContext) NewSoloFoundry added in v0.3.0

func (ctx *SoloContext) NewSoloFoundry(maxSupply interface{}, agent ...*SoloAgent) (*SoloFoundry, error)

NewSoloFoundry creates a new SoloFoundry

func (*SoloContext) OffLedger

func (ctx *SoloContext) OffLedger(agent *SoloAgent) wasmlib.ScFuncCallContext

OffLedger tells SoloContext to Post() the next request off-ledger

func (*SoloContext) Originator

func (ctx *SoloContext) Originator() *SoloAgent

Originator returns a SoloAgent representing the chain originator

func (*SoloContext) Sign

func (ctx *SoloContext) Sign(agent *SoloAgent) wasmlib.ScFuncCallContext

Sign is used to force a different agent for signing a Post() request

func (*SoloContext) SoloContextForCore

func (ctx *SoloContext) SoloContextForCore(t solo.TestContext, scName string, onLoad wasmhost.ScOnloadFunc) *SoloContext

func (*SoloContext) UpdateGasFees added in v0.3.0

func (ctx *SoloContext) UpdateGasFees()

func (*SoloContext) WaitForPendingRequests

func (ctx *SoloContext) WaitForPendingRequests(expectedRequests int, maxWait ...time.Duration) bool

WaitForPendingRequests waits for expectedRequests requests to be processed since the last call to WaitForPendingRequestsMark(). The function will wait for maxWait (default 5 seconds per request) duration before giving up with a timeout. The function returns false in case of a timeout.

func (*SoloContext) WaitForPendingRequestsMark added in v1.0.3

func (ctx *SoloContext) WaitForPendingRequestsMark()

WaitForPendingRequestsMark marks the current InPoolCounter to be used by a subsequent call to WaitForPendingRequests()

type SoloFoundry added in v0.3.0

type SoloFoundry struct {
	// contains filtered or unexported fields
}

func NewSoloFoundry added in v0.3.0

func NewSoloFoundry(ctx *SoloContext, maxSupply interface{}, agent ...*SoloAgent) (sf *SoloFoundry, err error)

func (*SoloFoundry) Destroy added in v0.3.0

func (sf *SoloFoundry) Destroy() error

func (*SoloFoundry) DestroyTokens added in v0.3.0

func (sf *SoloFoundry) DestroyTokens(amount interface{}) error

func (*SoloFoundry) Mint added in v0.3.0

func (sf *SoloFoundry) Mint(amount interface{}) error

func (*SoloFoundry) SN added in v0.3.0

func (sf *SoloFoundry) SN() uint32

func (*SoloFoundry) TokenID added in v0.3.0

func (sf *SoloFoundry) TokenID() wasmtypes.ScTokenID

type SoloSandbox

type SoloSandbox struct {
	// contains filtered or unexported fields
}

SoloSandbox acts as a temporary host side of the WasmLib Sandbox interface. It acts as a change-resistant layer to wrap changes to the Solo environment, to limit bothering users of WasmLib as little as possible with those changes. Note that only those functions that are related to invocation of SC requests are actually necessary here. These sandbox functions will never be called other than through the SC function call interface generated by schema tool.

func NewSoloSandbox

func NewSoloSandbox(ctx *SoloContext) *SoloSandbox

func (*SoloSandbox) Budget added in v0.3.0

func (s *SoloSandbox) Budget() uint64

func (*SoloSandbox) Burn added in v0.3.0

func (s *SoloSandbox) Burn(burnCode gas.BurnCode, par ...uint64)

func (*SoloSandbox) Burned added in v0.3.7

func (s *SoloSandbox) Burned() uint64

func (*SoloSandbox) Call

func (s *SoloSandbox) Call(funcNr int32, args []byte) []byte

func (*SoloSandbox) FnCall added in v1.0.3

func (s *SoloSandbox) FnCall(req *wasmrequests.CallRequest) []byte

func (*SoloSandbox) FnChainID added in v1.0.3

func (s *SoloSandbox) FnChainID() wasmtypes.ScChainID

func (*SoloSandbox) FnPost added in v1.0.3

func (s *SoloSandbox) FnPost(req *wasmrequests.PostRequest) []byte

func (*SoloSandbox) Logf added in v1.0.3

func (s *SoloSandbox) Logf(format string, args ...interface{})

func (*SoloSandbox) Panicf

func (s *SoloSandbox) Panicf(format string, args ...interface{})

func (*SoloSandbox) Tracef

func (s *SoloSandbox) Tracef(format string, args ...interface{})

Jump to

Keyboard shortcuts

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