Documentation ¶
Overview ¶
Package testcommon contains utility code for writing tests
Index ¶
- Constants
- Variables
- func AddNewOutputAccount(vmOutput *vmcommon.VMOutput, sender []byte, address []byte, balanceDelta int64, ...) *vmcommon.OutputAccount
- func AddTestSmartContractToWorld(world *worldmock.MockWorld, identifier string, code []byte) *worldmock.Account
- func DefaultTestContractCallInput() *vmcommon.ContractCallInput
- func DefaultTestContractCreateInput() *vmcommon.ContractCreateInput
- func DefaultTestVM(tb testing.TB, blockchain vmcommon.BlockchainHook) vmhost.VMHost
- func DefaultTestVMForCall(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.BlockchainHookStub)
- func DefaultTestVMForCallSigSegv(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.BlockchainHookStub)
- func DefaultTestVMForCallWithInstanceMocks(tb testing.TB) (vmhost.VMHost, *worldmock.MockWorld, *contextmock.InstanceBuilderMock)
- func DefaultTestVMForCallWithInstanceRecorderMock(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.InstanceBuilderRecorderMock)
- func DefaultTestVMForCallWithWorldMock(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *worldmock.MockWorld)
- func DefaultTestVMForDeployment(t *testing.T, _ uint64, newAddress []byte) (vmhost.VMHost, *contextmock.BlockchainHookStub)
- func DefaultTestVMForTwoSCs(t *testing.T, parentCode []byte, childCode []byte, parentSCBalance *big.Int, ...) (vmhost.VMHost, *contextmock.BlockchainHookStub)
- func DefaultTestVMWithGasSchedule(tb testing.TB, blockchain vmcommon.BlockchainHook, ...) vmhost.VMHost
- func DefaultTestVMWithWorldMock(tb testing.TB) (vmhost.VMHost, *worldmock.MockWorld)
- func DefaultTestVMWithWorldMockWithGasSchedule(tb testing.TB, customGasSchedule config.GasScheduleMap) (vmhost.VMHost, *worldmock.MockWorld)
- func GetSCCode(fileName string) []byte
- func GetTestSCCode(scName string, prefixToTestSCs ...string) []byte
- func GetTestSCCodeModule(scName string, moduleName string, prefixToTestSCs string) []byte
- func MakeTestSCAddress(identifier string) []byte
- func MakeVMOutput() *vmcommon.VMOutput
- func SimpleWasteGasMockMethod(instanceMock *mock.InstanceMock, gas uint64) func() *mock.InstanceMock
- type ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) Build() *vmcommon.ContractCallInput
- func (contractInput *ContractCallInputBuilder) WithArguments(arguments ...[]byte) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithCallType(callType vm.CallType) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithCallValue(value int64) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithCallerAddr(address []byte) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithCurrentTxHash(txHash []byte) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithDCTTokenName(dctTokenName []byte) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithDCTValue(dctValue *big.Int) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithFunction(function string) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithGasProvided(gas uint64) *ContractCallInputBuilder
- func (contractInput *ContractCallInputBuilder) WithRecipientAddr(address []byte) *ContractCallInputBuilder
- type ContractCreateInputBuilder
- func (contractInput *ContractCreateInputBuilder) Build() *vmcommon.ContractCreateInput
- func (contractInput *ContractCreateInputBuilder) WithArguments(arguments ...[]byte) *ContractCreateInputBuilder
- func (contractInput *ContractCreateInputBuilder) WithCallValue(callValue int64) *ContractCreateInputBuilder
- func (contractInput *ContractCreateInputBuilder) WithCallerAddr(address []byte) *ContractCreateInputBuilder
- func (contractInput *ContractCreateInputBuilder) WithContractCode(code []byte) *ContractCreateInputBuilder
- func (contractInput *ContractCreateInputBuilder) WithGasProvided(gas uint64) *ContractCreateInputBuilder
- type InstanceTestSmartContract
- type InstancesTestTemplate
- func (callerTest *InstancesTestTemplate) AndAssertResults(...)
- func (callerTest *InstancesTestTemplate) AndAssertResultsWithoutReset(...)
- func (callerTest *InstancesTestTemplate) GetVMHost() vmhost.VMHost
- func (callerTest *InstancesTestTemplate) WithContracts(usedContracts ...*InstanceTestSmartContract) *InstancesTestTemplate
- func (callerTest *InstancesTestTemplate) WithGasSchedule(gasSchedule config.GasScheduleMap) *InstancesTestTemplate
- func (callerTest *InstancesTestTemplate) WithInput(input *vmcommon.ContractCallInput) *InstancesTestTemplate
- func (callerTest *InstancesTestTemplate) WithSetup(setup func(vmhost.VMHost, *contextmock.BlockchainHookStub)) *InstancesTestTemplate
- func (callerTest *InstancesTestTemplate) WithWasmerSIGSEGVPassthrough(wasmerSIGSEGVPassthrough bool) *InstancesTestTemplate
- type MockBuiltin
- type MockInstancesTestTemplate
- func (callerTest *MockInstancesTestTemplate) AndAssertResults(assertResults func(world *worldmock.MockWorld, verify *VMOutputVerifier))
- func (callerTest *MockInstancesTestTemplate) WithContracts(usedContracts ...MockTestSmartContract) *MockInstancesTestTemplate
- func (callerTest *MockInstancesTestTemplate) WithInput(input *vmcommon.ContractCallInput) *MockInstancesTestTemplate
- func (callerTest *MockInstancesTestTemplate) WithSetup(setup func(vmhost.VMHost, *worldmock.MockWorld)) *MockInstancesTestTemplate
- func (callerTest *MockInstancesTestTemplate) WithWasmerSIGSEGVPassthrough(wasmerSIGSEGVPassthrough bool) *MockInstancesTestTemplate
- type MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithBalance(balance int64) *MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithCodeHash(codeHash []byte) *MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithCodeMetadata(codeMetadata []byte) *MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithConfig(config interface{}) *MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithMethods(initMethods ...func(*mock.InstanceMock, interface{})) MockTestSmartContract
- func (mockSC *MockTestSmartContract) WithOwnerAddress(ownerAddress []byte) *MockTestSmartContract
- type StoreEntry
- type TestCreateTemplateConfig
- func (callerTest *TestCreateTemplateConfig) AndAssertResults(assertResults func(*contextmock.BlockchainHookStub, *VMOutputVerifier))
- func (callerTest *TestCreateTemplateConfig) AndAssertResultsWithoutReset(assertResults func(*contextmock.BlockchainHookStub, *VMOutputVerifier))
- func (callerTest *TestCreateTemplateConfig) WithAddress(address []byte) *TestCreateTemplateConfig
- func (callerTest *TestCreateTemplateConfig) WithInput(input *vmcommon.ContractCreateInput) *TestCreateTemplateConfig
- func (callerTest *TestCreateTemplateConfig) WithSetup(setup func(vmhost.VMHost, *contextmock.BlockchainHookStub)) *TestCreateTemplateConfig
- type TransferEntry
- func (transferEntry *TransferEntry) WithCallType(callType vm.CallType) *TransferEntry
- func (transferEntry *TransferEntry) WithData(data []byte) *TransferEntry
- func (transferEntry *TransferEntry) WithGasLimit(gas uint64) *TransferEntry
- func (transferEntry *TransferEntry) WithGasLocked(gas uint64) *TransferEntry
- func (transferEntry *TransferEntry) WithValue(value *big.Int) TransferEntry
- type VMOutputVerifier
- func (v *VMOutputVerifier) Balance(address []byte, balance int64) *VMOutputVerifier
- func (v *VMOutputVerifier) BalanceDelta(address []byte, balanceDelta int64) *VMOutputVerifier
- func (v *VMOutputVerifier) BytesAddedToStorage(address []byte, bytesAdded int) *VMOutputVerifier
- func (v *VMOutputVerifier) BytesDeletedFromStorage(address []byte, bytesDelted int) *VMOutputVerifier
- func (v *VMOutputVerifier) Code(address []byte, code []byte) *VMOutputVerifier
- func (v *VMOutputVerifier) CodeDeployerAddress(address []byte, codeDeployerAddress []byte) *VMOutputVerifier
- func (v *VMOutputVerifier) CodeMetadata(address []byte, codeMetadata []byte) *VMOutputVerifier
- func (v *VMOutputVerifier) ContractInvalid() *VMOutputVerifier
- func (v *VMOutputVerifier) ContractNotFound() *VMOutputVerifier
- func (v *VMOutputVerifier) ExecutionFailed() *VMOutputVerifier
- func (v *VMOutputVerifier) FunctionNotFound() *VMOutputVerifier
- func (v *VMOutputVerifier) GasRemaining(gas uint64) *VMOutputVerifier
- func (v *VMOutputVerifier) GasUsed(address []byte, gas uint64) *VMOutputVerifier
- func (v *VMOutputVerifier) HasRuntimeErrorAndInfo(message string, otherInfo string) *VMOutputVerifier
- func (v *VMOutputVerifier) HasRuntimeErrors(messages ...string) *VMOutputVerifier
- func (v *VMOutputVerifier) Logs(logs ...vmcommon.LogEntry) *VMOutputVerifier
- func (v *VMOutputVerifier) Nonce(address []byte, nonce uint64) *VMOutputVerifier
- func (v *VMOutputVerifier) Ok() *VMOutputVerifier
- func (v *VMOutputVerifier) OutOfGas() *VMOutputVerifier
- func (v *VMOutputVerifier) ReturnCode(code vmcommon.ReturnCode) *VMOutputVerifier
- func (v *VMOutputVerifier) ReturnData(returnData ...[]byte) *VMOutputVerifier
- func (v *VMOutputVerifier) ReturnMessage(message string) *VMOutputVerifier
- func (v *VMOutputVerifier) ReturnMessageContains(message string) *VMOutputVerifier
- func (v *VMOutputVerifier) Storage(expectedEntries ...StoreEntry) *VMOutputVerifier
- func (v *VMOutputVerifier) Transfers(transfers ...TransferEntry) *VMOutputVerifier
- func (v *VMOutputVerifier) UserError() *VMOutputVerifier
Constants ¶
const AddressSize = 32
AddressSize is the size of an account address, in bytes.
Variables ¶
var ChildAddress = MakeTestSCAddress("childSC")
ChildAddress is an exposed value to use in tests
var ChildCompilationCostDestCtx uint64
ChildCompilationCostDestCtx value exposed for test usage
var ChildCompilationCostSameCtx uint64
ChildCompilationCostSameCtx value exposed for test usage
var ChildData = []byte("childData")
ChildData value exposed for test usage
var ChildFinish = []byte("childFinish")
ChildFinish value exposed for test usage
var ChildKey = []byte("childKey........................")
ChildKey value exposed for test usage
var ChildKeyB = []byte("childKeyB........................")
ChildKeyB value exposed for test usage
var ChildTransferReceiver = []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0fchildTransferReceiver.")
ChildTransferReceiver value exposed for test usage
var DCTTestTokenName = []byte("TTT-010101")
DCTTestTokenName is an exposed value to use in tests
var DCTTransferGasCost = uint64(1)
DCTTransferGasCost is an exposed value to use in tests
var DefaultCodeMetadata = []byte{3, 0}
DefaultCodeMetadata is an exposed value to use in tests
var DefaultVMType = []byte{0xF, 0xF}
DefaultVMType is an exposed value to use in tests
var ErrAccountNotFound = errors.New("account not found")
ErrAccountNotFound is an exposed value to use in tests
var GasProvided = uint64(1000000)
GasProvided value exposed for test usage
var NephewAddress = MakeTestSCAddress("NephewAddress")
NephewAddress is an exposed value to use in tests
var ParentAddress = MakeTestSCAddress("parentSC")
ParentAddress is an exposed value to use in tests
var ParentCompilationCostDestCtx uint64
ParentCompilationCostDestCtx value exposed for test usage
var ParentCompilationCostSameCtx uint64
ParentCompilationCostSameCtx value exposed for test usage
var ParentDataA = []byte("parentDataA")
ParentDataA value exposed for test usage
var ParentDataB = []byte("parentDataB")
ParentDataB value exposed for test usage
var ParentFinishA = []byte("parentFinishA")
ParentFinishA value exposed for test usage
var ParentFinishB = []byte("parentFinishB")
ParentFinishB value exposed for test usage
var ParentKeyA = []byte("parentKeyA......................")
ParentKeyA value exposed for test usage
var ParentKeyB = []byte("parentKeyB......................")
ParentKeyB value exposed for test usage
var ParentTransferData = []byte("parentTransferData")
ParentTransferData value exposed for test usage
var ParentTransferReceiver = []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0fparentTransferReceiver")
ParentTransferReceiver value exposed for test usage
var ParentTransferValue = int64(42)
ParentTransferValue value exposed for test usage
var RecursiveIterationBigCounterKey = []byte("recursiveIterationBigCounter....")
RecursiveIterationBigCounterKey value exposed for test usage
var RecursiveIterationCounterKey = []byte("recursiveIterationCounter.......")
RecursiveIterationCounterKey value exposed for test usage
var SCAddressPrefix = []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0f")
SCAddressPrefix is the prefix of any smart contract address used for testing.
var ThirdPartyAddress = []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0fthirdPartyAddress.....")
ThirdPartyAddress value exposed for test usage
var UserAddress = []byte("userAccount.....................")
UserAddress is an exposed value to use in tests
var UserAddress2 = []byte("userAccount2....................")
UserAddress2 is an exposed value to use in tests
var VaultAddress = []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x0fvaultAddress..........")
VaultAddress value exposed for test usage
Functions ¶
func AddNewOutputAccount ¶
func AddNewOutputAccount(vmOutput *vmcommon.VMOutput, sender []byte, address []byte, balanceDelta int64, data []byte) *vmcommon.OutputAccount
AddNewOutputAccount creates a new vmcommon.OutputAccount from the provided arguments and adds it to OutputAccounts of the provided vmOutput
func AddTestSmartContractToWorld ¶
func AddTestSmartContractToWorld(world *worldmock.MockWorld, identifier string, code []byte) *worldmock.Account
AddTestSmartContractToWorld directly deploys the provided code into the given MockWorld under a SC address built with the given identifier.
func DefaultTestContractCallInput ¶
func DefaultTestContractCallInput() *vmcommon.ContractCallInput
DefaultTestContractCallInput creates a vmcommon.ContractCallInput struct with default values.
func DefaultTestContractCreateInput ¶
func DefaultTestContractCreateInput() *vmcommon.ContractCreateInput
DefaultTestContractCreateInput creates a vmcommon.ContractCreateInput struct with default values.
func DefaultTestVM ¶
DefaultTestVM creates a host configured with a blockchain hook
func DefaultTestVMForCall ¶
func DefaultTestVMForCall(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.BlockchainHookStub)
DefaultTestVMForCall creates a BlockchainHookStub
func DefaultTestVMForCallSigSegv ¶
func DefaultTestVMForCallSigSegv(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.BlockchainHookStub)
DefaultTestVMForCallSigSegv creates a BlockchainHookStub and a host
func DefaultTestVMForCallWithInstanceMocks ¶
func DefaultTestVMForCallWithInstanceMocks(tb testing.TB) (vmhost.VMHost, *worldmock.MockWorld, *contextmock.InstanceBuilderMock)
DefaultTestVMForCallWithInstanceMocks creates an InstanceBuilderMock
func DefaultTestVMForCallWithInstanceRecorderMock ¶
func DefaultTestVMForCallWithInstanceRecorderMock(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *contextmock.InstanceBuilderRecorderMock)
DefaultTestVMForCallWithInstanceRecorderMock creates an InstanceBuilderRecorderMock
func DefaultTestVMForCallWithWorldMock ¶
func DefaultTestVMForCallWithWorldMock(tb testing.TB, code []byte, balance *big.Int) (vmhost.VMHost, *worldmock.MockWorld)
DefaultTestVMForCallWithWorldMock creates a MockWorld
func DefaultTestVMForDeployment ¶
func DefaultTestVMForDeployment(t *testing.T, _ uint64, newAddress []byte) (vmhost.VMHost, *contextmock.BlockchainHookStub)
DefaultTestVMForDeployment creates an VM vmHost configured for testing deployments
func DefaultTestVMForTwoSCs ¶
func DefaultTestVMForTwoSCs( t *testing.T, parentCode []byte, childCode []byte, parentSCBalance *big.Int, childSCBalance *big.Int, ) (vmhost.VMHost, *contextmock.BlockchainHookStub)
DefaultTestVMForTwoSCs creates an VM vmHost configured for testing calls between 2 SmartContracts
func DefaultTestVMWithGasSchedule ¶
func DefaultTestVMWithGasSchedule( tb testing.TB, blockchain vmcommon.BlockchainHook, customGasSchedule config.GasScheduleMap, wasmerSIGSEGVPassthrough bool, ) vmhost.VMHost
DefaultTestVMWithGasSchedule creates a host with the provided blockchain hook and gas schedule
func DefaultTestVMWithWorldMock ¶
DefaultTestVMWithWorldMock creates a host configured with a mock world
func DefaultTestVMWithWorldMockWithGasSchedule ¶
func DefaultTestVMWithWorldMockWithGasSchedule(tb testing.TB, customGasSchedule config.GasScheduleMap) (vmhost.VMHost, *worldmock.MockWorld)
DefaultTestVMWithWorldMockWithGasSchedule creates a host configured with a mock world
func GetTestSCCode ¶
GetTestSCCode retrieves the bytecode of a WASM testing contract
func GetTestSCCodeModule ¶
GetTestSCCodeModule retrieves the bytecode of a WASM testing contract, given a specific name of the WASM module
func MakeTestSCAddress ¶
MakeTestSCAddress generates a new smart contract address to be used for testing based on the given identifier.
func MakeVMOutput ¶
MakeVMOutput creates a vmcommon.VMOutput struct with default values
func SimpleWasteGasMockMethod ¶
func SimpleWasteGasMockMethod(instanceMock *mock.InstanceMock, gas uint64) func() *mock.InstanceMock
SimpleWasteGasMockMethod is a simple waste gas mock method
Types ¶
type ContractCallInputBuilder ¶
type ContractCallInputBuilder struct {
vmcommon.ContractCallInput
}
ContractCallInputBuilder extends a ContractCallInput for extra building functionality during testing
func CreateTestContractCallInputBuilder ¶
func CreateTestContractCallInputBuilder() *ContractCallInputBuilder
CreateTestContractCallInputBuilder is a builder for ContractCallInputBuilder
func (*ContractCallInputBuilder) Build ¶
func (contractInput *ContractCallInputBuilder) Build() *vmcommon.ContractCallInput
Build completes the build of a ContractCallInput
func (*ContractCallInputBuilder) WithArguments ¶
func (contractInput *ContractCallInputBuilder) WithArguments(arguments ...[]byte) *ContractCallInputBuilder
WithArguments provides the arguments to be called for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithCallType ¶
func (contractInput *ContractCallInputBuilder) WithCallType(callType vm.CallType) *ContractCallInputBuilder
WithCallType provides the arguments to be called for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithCallValue ¶
func (contractInput *ContractCallInputBuilder) WithCallValue(value int64) *ContractCallInputBuilder
WithCallValue provides the value transferred to the called contract
func (*ContractCallInputBuilder) WithCallerAddr ¶
func (contractInput *ContractCallInputBuilder) WithCallerAddr(address []byte) *ContractCallInputBuilder
WithCallerAddr provides the caller address of ContractCallInputBuilder
func (*ContractCallInputBuilder) WithCurrentTxHash ¶
func (contractInput *ContractCallInputBuilder) WithCurrentTxHash(txHash []byte) *ContractCallInputBuilder
WithCurrentTxHash provides the CurrentTxHash for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithDCTTokenName ¶
func (contractInput *ContractCallInputBuilder) WithDCTTokenName(dctTokenName []byte) *ContractCallInputBuilder
WithDCTTokenName provides the DCTTokenName for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithDCTValue ¶
func (contractInput *ContractCallInputBuilder) WithDCTValue(dctValue *big.Int) *ContractCallInputBuilder
WithDCTValue provides the DCTValue for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithFunction ¶
func (contractInput *ContractCallInputBuilder) WithFunction(function string) *ContractCallInputBuilder
WithFunction provides the function to be called for ContractCallInputBuilder
func (*ContractCallInputBuilder) WithGasProvided ¶
func (contractInput *ContractCallInputBuilder) WithGasProvided(gas uint64) *ContractCallInputBuilder
WithGasProvided provides the gas of ContractCallInputBuilder
func (*ContractCallInputBuilder) WithRecipientAddr ¶
func (contractInput *ContractCallInputBuilder) WithRecipientAddr(address []byte) *ContractCallInputBuilder
WithRecipientAddr provides the recepient address of ContractCallInputBuilder
type ContractCreateInputBuilder ¶
type ContractCreateInputBuilder struct {
vmcommon.ContractCreateInput
}
ContractCreateInputBuilder extends a ContractCreateInput for extra building functionality during testing
func CreateTestContractCreateInputBuilder ¶
func CreateTestContractCreateInputBuilder() *ContractCreateInputBuilder
CreateTestContractCreateInputBuilder is a builder for ContractCreateInputBuilder
func (*ContractCreateInputBuilder) Build ¶
func (contractInput *ContractCreateInputBuilder) Build() *vmcommon.ContractCreateInput
Build completes the build of a ContractCreateInput
func (*ContractCreateInputBuilder) WithArguments ¶
func (contractInput *ContractCreateInputBuilder) WithArguments(arguments ...[]byte) *ContractCreateInputBuilder
WithArguments provides the Arguments for a ContractCreateInputBuilder
func (*ContractCreateInputBuilder) WithCallValue ¶
func (contractInput *ContractCreateInputBuilder) WithCallValue(callValue int64) *ContractCreateInputBuilder
WithCallValue provides the CallValue for a ContractCreateInputBuilder
func (*ContractCreateInputBuilder) WithCallerAddr ¶
func (contractInput *ContractCreateInputBuilder) WithCallerAddr(address []byte) *ContractCreateInputBuilder
WithCallerAddr provides the CallerAddr for a ContractCreateInputBuilder
func (*ContractCreateInputBuilder) WithContractCode ¶
func (contractInput *ContractCreateInputBuilder) WithContractCode(code []byte) *ContractCreateInputBuilder
WithContractCode provides the ContractCode for a ContractCreateInputBuilder
func (*ContractCreateInputBuilder) WithGasProvided ¶
func (contractInput *ContractCreateInputBuilder) WithGasProvided(gas uint64) *ContractCreateInputBuilder
WithGasProvided provides the GasProvided for a ContractCreateInputBuilder
type InstanceTestSmartContract ¶
type InstanceTestSmartContract struct {
// contains filtered or unexported fields
}
InstanceTestSmartContract represents the config data for the smart contract instance to be tested
func CreateInstanceContract ¶
func CreateInstanceContract(address []byte) *InstanceTestSmartContract
CreateInstanceContract build a contract to be used in a test creted with BuildInstanceCallTest
func (*InstanceTestSmartContract) WithBalance ¶
func (mockSC *InstanceTestSmartContract) WithBalance(balance int64) *InstanceTestSmartContract
WithBalance provides the balance for the InstanceTestSmartContract
func (*InstanceTestSmartContract) WithCode ¶
func (mockSC *InstanceTestSmartContract) WithCode(code []byte) *InstanceTestSmartContract
WithCode provides the code for the InstanceTestSmartContract
func (*InstanceTestSmartContract) WithConfig ¶
func (mockSC *InstanceTestSmartContract) WithConfig(config interface{}) *InstanceTestSmartContract
WithConfig provides the config object for the InstanceTestSmartContract
type InstancesTestTemplate ¶
type InstancesTestTemplate struct {
// contains filtered or unexported fields
}
InstancesTestTemplate holds the data to build a contract call test
func BuildInstanceCallTest ¶
func BuildInstanceCallTest(tb testing.TB) *InstancesTestTemplate
BuildInstanceCallTest starts the building process for a contract call test
func (*InstancesTestTemplate) AndAssertResults ¶
func (callerTest *InstancesTestTemplate) AndAssertResults(assertResults func(vmhost.VMHost, *contextmock.BlockchainHookStub, *VMOutputVerifier))
AndAssertResults starts the test and asserts the results
func (*InstancesTestTemplate) AndAssertResultsWithoutReset ¶
func (callerTest *InstancesTestTemplate) AndAssertResultsWithoutReset(assertResults func(vmhost.VMHost, *contextmock.BlockchainHookStub, *VMOutputVerifier))
AndAssertResultsWithoutReset starts the test and asserts the results
func (*InstancesTestTemplate) GetVMHost ¶
func (callerTest *InstancesTestTemplate) GetVMHost() vmhost.VMHost
GetVMHost returns the host instantiated in this test template
func (*InstancesTestTemplate) WithContracts ¶
func (callerTest *InstancesTestTemplate) WithContracts(usedContracts ...*InstanceTestSmartContract) *InstancesTestTemplate
WithContracts provides the contracts to be used by the contract call test
func (*InstancesTestTemplate) WithGasSchedule ¶
func (callerTest *InstancesTestTemplate) WithGasSchedule(gasSchedule config.GasScheduleMap) *InstancesTestTemplate
WithGasSchedule provides gas schedule for the test
func (*InstancesTestTemplate) WithInput ¶
func (callerTest *InstancesTestTemplate) WithInput(input *vmcommon.ContractCallInput) *InstancesTestTemplate
WithInput provides the ContractCallInput to be used by the contract call test
func (*InstancesTestTemplate) WithSetup ¶
func (callerTest *InstancesTestTemplate) WithSetup(setup func(vmhost.VMHost, *contextmock.BlockchainHookStub)) *InstancesTestTemplate
WithSetup provides the setup function to be used by the contract call test
func (*InstancesTestTemplate) WithWasmerSIGSEGVPassthrough ¶
func (callerTest *InstancesTestTemplate) WithWasmerSIGSEGVPassthrough(wasmerSIGSEGVPassthrough bool) *InstancesTestTemplate
WithWasmerSIGSEGVPassthrough sets the wasmerSIGSEGVPassthrough flag
type MockBuiltin ¶
type MockBuiltin struct { ProcessBuiltinFunctionCall func(acntSnd, _ vmcommon.UserAccountHandler, vmInput *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) // contains filtered or unexported fields }
MockBuiltin defined the functions that can be replaced in order to mock a builtin
func (*MockBuiltin) IsInterfaceNil ¶
func (m *MockBuiltin) IsInterfaceNil() bool
IsInterfaceNil - see BuiltinFunction.IsInterfaceNil()
func (*MockBuiltin) ProcessBuiltinFunction ¶
func (m *MockBuiltin) ProcessBuiltinFunction(acntSnd, acntRcv vmcommon.UserAccountHandler, vmInput *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
ProcessBuiltinFunction - see BuiltinFunction.ProcessBuiltInFunction()
func (*MockBuiltin) SetNewGasConfig ¶
func (m *MockBuiltin) SetNewGasConfig(gasCost *vmcommon.GasCost)
SetNewGasConfig - see BuiltinFunction.SetNewGasConfig()
type MockInstancesTestTemplate ¶
type MockInstancesTestTemplate struct {
// contains filtered or unexported fields
}
MockInstancesTestTemplate holds the data to build a mock contract call test
func BuildMockInstanceCallTest ¶
func BuildMockInstanceCallTest(tb testing.TB) *MockInstancesTestTemplate
BuildMockInstanceCallTest starts the building process for a mock contract call test
func (*MockInstancesTestTemplate) AndAssertResults ¶
func (callerTest *MockInstancesTestTemplate) AndAssertResults(assertResults func(world *worldmock.MockWorld, verify *VMOutputVerifier))
AndAssertResults provides the function that will aserts the results
func (*MockInstancesTestTemplate) WithContracts ¶
func (callerTest *MockInstancesTestTemplate) WithContracts(usedContracts ...MockTestSmartContract) *MockInstancesTestTemplate
WithContracts provides the contracts to be used by the mock contract call test
func (*MockInstancesTestTemplate) WithInput ¶
func (callerTest *MockInstancesTestTemplate) WithInput(input *vmcommon.ContractCallInput) *MockInstancesTestTemplate
WithInput provides the ContractCallInput to be used by the mock contract call test
func (*MockInstancesTestTemplate) WithSetup ¶
func (callerTest *MockInstancesTestTemplate) WithSetup(setup func(vmhost.VMHost, *worldmock.MockWorld)) *MockInstancesTestTemplate
WithSetup provides the setup function to be used by the mock contract call test
func (*MockInstancesTestTemplate) WithWasmerSIGSEGVPassthrough ¶
func (callerTest *MockInstancesTestTemplate) WithWasmerSIGSEGVPassthrough(wasmerSIGSEGVPassthrough bool) *MockInstancesTestTemplate
WithWasmerSIGSEGVPassthrough sets the wasmerSIGSEGVPassthrough flag
type MockTestSmartContract ¶
type MockTestSmartContract struct {
// contains filtered or unexported fields
}
MockTestSmartContract represents the config data for the mock smart contract instance to be tested
func CreateMockContract ¶
func CreateMockContract(address []byte) *MockTestSmartContract
CreateMockContract build a contract to be used in a test creted with BuildMockInstanceCallTest
func CreateMockContractOnShard ¶
func CreateMockContractOnShard(address []byte, shardID uint32) *MockTestSmartContract
CreateMockContractOnShard build a contract to be used in a test creted with BuildMockInstanceCallTest
func (*MockTestSmartContract) WithBalance ¶
func (mockSC *MockTestSmartContract) WithBalance(balance int64) *MockTestSmartContract
WithBalance provides the balance for the MockTestSmartContract
func (*MockTestSmartContract) WithCodeHash ¶
func (mockSC *MockTestSmartContract) WithCodeHash(codeHash []byte) *MockTestSmartContract
WithCodeHash provides the code hash for the MockTestSmartContract
func (*MockTestSmartContract) WithCodeMetadata ¶
func (mockSC *MockTestSmartContract) WithCodeMetadata(codeMetadata []byte) *MockTestSmartContract
WithCodeMetadata provides the code metadata for the MockTestSmartContract
func (*MockTestSmartContract) WithConfig ¶
func (mockSC *MockTestSmartContract) WithConfig(config interface{}) *MockTestSmartContract
WithConfig provides the config object for the MockTestSmartContract
func (*MockTestSmartContract) WithMethods ¶
func (mockSC *MockTestSmartContract) WithMethods(initMethods ...func(*mock.InstanceMock, interface{})) MockTestSmartContract
WithMethods provides the methods for the MockTestSmartContract
func (*MockTestSmartContract) WithOwnerAddress ¶
func (mockSC *MockTestSmartContract) WithOwnerAddress(ownerAddress []byte) *MockTestSmartContract
WithOwnerAddress provides the owner address for the MockTestSmartContract
type StoreEntry ¶
type StoreEntry struct {
// contains filtered or unexported fields
}
StoreEntry holds the data for a storage assertion
func CreateStoreEntry ¶
func CreateStoreEntry(address []byte) *StoreEntry
CreateStoreEntry creates the data for a storage assertion
func (*StoreEntry) WithKey ¶
func (storeEntry *StoreEntry) WithKey(key []byte) *StoreEntry
WithKey sets the key for a storage assertion
func (*StoreEntry) WithValue ¶
func (storeEntry *StoreEntry) WithValue(value []byte) StoreEntry
WithValue sets the value for a storage assertion
type TestCreateTemplateConfig ¶
type TestCreateTemplateConfig struct {
// contains filtered or unexported fields
}
TestCreateTemplateConfig holds the data to build a contract creation test
func BuildInstanceCreatorTest ¶
func BuildInstanceCreatorTest(t *testing.T) *TestCreateTemplateConfig
BuildInstanceCreatorTest starts the building process for a contract creation test
func (*TestCreateTemplateConfig) AndAssertResults ¶
func (callerTest *TestCreateTemplateConfig) AndAssertResults(assertResults func(*contextmock.BlockchainHookStub, *VMOutputVerifier))
AndAssertResults provides the function that will aserts the results
func (*TestCreateTemplateConfig) AndAssertResultsWithoutReset ¶
func (callerTest *TestCreateTemplateConfig) AndAssertResultsWithoutReset(assertResults func(*contextmock.BlockchainHookStub, *VMOutputVerifier))
AndAssertResultsWithoutReset provides the function that will aserts the results
func (*TestCreateTemplateConfig) WithAddress ¶
func (callerTest *TestCreateTemplateConfig) WithAddress(address []byte) *TestCreateTemplateConfig
WithAddress provides the address for a TestCreateTemplateConfig
func (*TestCreateTemplateConfig) WithInput ¶
func (callerTest *TestCreateTemplateConfig) WithInput(input *vmcommon.ContractCreateInput) *TestCreateTemplateConfig
WithInput provides the ContractCreateInput for a TestCreateTemplateConfig
func (*TestCreateTemplateConfig) WithSetup ¶
func (callerTest *TestCreateTemplateConfig) WithSetup(setup func(vmhost.VMHost, *contextmock.BlockchainHookStub)) *TestCreateTemplateConfig
WithSetup provides the setup function for a TestCreateTemplateConfig
type TransferEntry ¶
type TransferEntry struct { vmcommon.OutputTransfer // contains filtered or unexported fields }
TransferEntry holds the data for an output transfer assertion
func CreateTransferEntry ¶
func CreateTransferEntry(senderAddress []byte, receiverAddress []byte) *TransferEntry
CreateTransferEntry creates the data for an output transfer assertion
func (*TransferEntry) WithCallType ¶
func (transferEntry *TransferEntry) WithCallType(callType vm.CallType) *TransferEntry
WithCallType create sets the data for an output transfer assertion
func (*TransferEntry) WithData ¶
func (transferEntry *TransferEntry) WithData(data []byte) *TransferEntry
WithData create sets the data for an output transfer assertion
func (*TransferEntry) WithGasLimit ¶
func (transferEntry *TransferEntry) WithGasLimit(gas uint64) *TransferEntry
WithGasLimit create sets the data for an output transfer assertion
func (*TransferEntry) WithGasLocked ¶
func (transferEntry *TransferEntry) WithGasLocked(gas uint64) *TransferEntry
WithGasLocked create sets the data for an output transfer assertion
func (*TransferEntry) WithValue ¶
func (transferEntry *TransferEntry) WithValue(value *big.Int) TransferEntry
WithValue create sets the value for an output transfer assertion
type VMOutputVerifier ¶
type VMOutputVerifier struct { VmOutput *vmcommon.VMOutput AllErrors vmhost.WrappableError T testing.TB }
VMOutputVerifier holds the output to be verified
func NewVMOutputVerifier ¶
NewVMOutputVerifier builds a new verifier
func NewVMOutputVerifierWithAllErrors ¶
func NewVMOutputVerifierWithAllErrors(t testing.TB, vmOutput *vmcommon.VMOutput, err error, allErrors error) *VMOutputVerifier
NewVMOutputVerifierWithAllErrors builds a new verifier with all errors included
func (*VMOutputVerifier) Balance ¶
func (v *VMOutputVerifier) Balance(address []byte, balance int64) *VMOutputVerifier
Balance verifies if Balance of the specified account is the same as the provided one
func (*VMOutputVerifier) BalanceDelta ¶
func (v *VMOutputVerifier) BalanceDelta(address []byte, balanceDelta int64) *VMOutputVerifier
BalanceDelta verifies if BalanceDelta of the specified account is the same as the provided one
func (*VMOutputVerifier) BytesAddedToStorage ¶
func (v *VMOutputVerifier) BytesAddedToStorage(address []byte, bytesAdded int) *VMOutputVerifier
BytesAddedToStorage verifies the number of bytes added to storage
func (*VMOutputVerifier) BytesDeletedFromStorage ¶
func (v *VMOutputVerifier) BytesDeletedFromStorage(address []byte, bytesDelted int) *VMOutputVerifier
BytesDeletedFromStorage verifies the number of bytes deleted from storage
func (*VMOutputVerifier) Code ¶
func (v *VMOutputVerifier) Code(address []byte, code []byte) *VMOutputVerifier
Code verifies if Code of the specified account is the same as the provided one
func (*VMOutputVerifier) CodeDeployerAddress ¶
func (v *VMOutputVerifier) CodeDeployerAddress(address []byte, codeDeployerAddress []byte) *VMOutputVerifier
CodeDeployerAddress if CodeDeployerAddress of the specified account is the same as the provided one
func (*VMOutputVerifier) CodeMetadata ¶
func (v *VMOutputVerifier) CodeMetadata(address []byte, codeMetadata []byte) *VMOutputVerifier
CodeMetadata if CodeMetadata of the specified account is the same as the provided one
func (*VMOutputVerifier) ContractInvalid ¶
func (v *VMOutputVerifier) ContractInvalid() *VMOutputVerifier
ContractInvalid verifies if return code is vmcommon.ContractInvalid
func (*VMOutputVerifier) ContractNotFound ¶
func (v *VMOutputVerifier) ContractNotFound() *VMOutputVerifier
ContractNotFound verifies if return code is vmcommon.ContractNotFound
func (*VMOutputVerifier) ExecutionFailed ¶
func (v *VMOutputVerifier) ExecutionFailed() *VMOutputVerifier
ExecutionFailed verifies if return code is vmcommon.ExecutionFailed
func (*VMOutputVerifier) FunctionNotFound ¶
func (v *VMOutputVerifier) FunctionNotFound() *VMOutputVerifier
FunctionNotFound verifies if return code is vmcommon.FunctionNotFound
func (*VMOutputVerifier) GasRemaining ¶
func (v *VMOutputVerifier) GasRemaining(gas uint64) *VMOutputVerifier
GasRemaining verifies if GasRemaining of the specified account is the same as the provided one
func (*VMOutputVerifier) GasUsed ¶
func (v *VMOutputVerifier) GasUsed(address []byte, gas uint64) *VMOutputVerifier
GasUsed verifies if GasUsed of the specified account is the same as the provided one
func (*VMOutputVerifier) HasRuntimeErrorAndInfo ¶
func (v *VMOutputVerifier) HasRuntimeErrorAndInfo(message string, otherInfo string) *VMOutputVerifier
HasRuntimeErrorAndInfo verifies if the provided errors are present in the runtime context
func (*VMOutputVerifier) HasRuntimeErrors ¶
func (v *VMOutputVerifier) HasRuntimeErrors(messages ...string) *VMOutputVerifier
HasRuntimeErrors verifies if the provided errors are present in the runtime context
func (*VMOutputVerifier) Logs ¶
func (v *VMOutputVerifier) Logs(logs ...vmcommon.LogEntry) *VMOutputVerifier
Logs verifies if Logs is the same as the provided one
func (*VMOutputVerifier) Nonce ¶
func (v *VMOutputVerifier) Nonce(address []byte, nonce uint64) *VMOutputVerifier
Nonce verifies if Nonce of the specified account is the same as the provided one
func (*VMOutputVerifier) Ok ¶
func (v *VMOutputVerifier) Ok() *VMOutputVerifier
Ok verifies if return code is vmcommon.Ok
func (*VMOutputVerifier) OutOfGas ¶
func (v *VMOutputVerifier) OutOfGas() *VMOutputVerifier
OutOfGas verifies if return code is vmcommon.OutOfGas
func (*VMOutputVerifier) ReturnCode ¶
func (v *VMOutputVerifier) ReturnCode(code vmcommon.ReturnCode) *VMOutputVerifier
ReturnCode verifies if ReturnCode of output is the same as the provided one
func (*VMOutputVerifier) ReturnData ¶
func (v *VMOutputVerifier) ReturnData(returnData ...[]byte) *VMOutputVerifier
ReturnData verifies if ReturnData is the same as the provided one
func (*VMOutputVerifier) ReturnMessage ¶
func (v *VMOutputVerifier) ReturnMessage(message string) *VMOutputVerifier
ReturnMessage verifies if ReturnMessage of output is the same as the provided one
func (*VMOutputVerifier) ReturnMessageContains ¶
func (v *VMOutputVerifier) ReturnMessageContains(message string) *VMOutputVerifier
ReturnMessageContains verifies if ReturnMessage of output contains the provided one
func (*VMOutputVerifier) Storage ¶
func (v *VMOutputVerifier) Storage(expectedEntries ...StoreEntry) *VMOutputVerifier
Storage verifies if StorageUpdate(s) for the speficied accounts are the same as the provided ones
func (*VMOutputVerifier) Transfers ¶
func (v *VMOutputVerifier) Transfers(transfers ...TransferEntry) *VMOutputVerifier
Transfers verifies if OutputTransfer(s) for the speficied accounts are the same as the provided ones
func (*VMOutputVerifier) UserError ¶
func (v *VMOutputVerifier) UserError() *VMOutputVerifier
UserError verifies if return code is vmcommon.UserError