2019-11-18 16:31:27 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/state"
|
2019-11-18 16:31:27 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
2019-12-04 12:24:49 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/internal/random"
|
2019-11-18 16:31:27 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/smartcontract"
|
2019-12-04 09:27:04 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/smartcontract/trigger"
|
2019-11-18 16:31:27 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* Missing tests:
|
|
|
|
* TestTxGetReferences
|
|
|
|
* TestTxGetUnspentCoins
|
|
|
|
* TestTxGetWitnesses
|
|
|
|
* TestBcGetAccount
|
|
|
|
* TestBcGetAsset
|
|
|
|
* TestAccountGetBalance
|
|
|
|
* TestAccountIsStandard
|
|
|
|
* TestCreateContractStateFromVM
|
|
|
|
* TestContractCreate
|
|
|
|
* TestContractMigrate
|
|
|
|
* TestAssetCreate
|
|
|
|
* TestAssetRenew
|
|
|
|
* TestRuntimeSerialize
|
|
|
|
* TestRuntimeDeserialize
|
|
|
|
*/
|
|
|
|
|
|
|
|
func TestHeaderGetVersion(t *testing.T) {
|
|
|
|
v, block, context := createVMAndPushBlock(t)
|
|
|
|
|
|
|
|
err := context.headerGetVersion(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().(*big.Int)
|
|
|
|
require.Equal(t, uint64(block.Version), value.Uint64())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeaderGetVersion_Negative(t *testing.T) {
|
|
|
|
v := vm.New()
|
|
|
|
block := newDumbBlock()
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), block, nil)
|
2019-11-18 16:31:27 +00:00
|
|
|
v.Estack().PushVal(vm.NewBoolItem(false))
|
|
|
|
|
|
|
|
err := context.headerGetVersion(v)
|
|
|
|
require.Errorf(t, err, "value is not a header or block")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeaderGetConsensusData(t *testing.T) {
|
|
|
|
v, block, context := createVMAndPushBlock(t)
|
|
|
|
|
|
|
|
err := context.headerGetConsensusData(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().(*big.Int)
|
|
|
|
require.Equal(t, block.ConsensusData, value.Uint64())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeaderGetMerkleRoot(t *testing.T) {
|
|
|
|
v, block, context := createVMAndPushBlock(t)
|
|
|
|
|
|
|
|
err := context.headerGetMerkleRoot(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value()
|
2019-11-27 09:23:18 +00:00
|
|
|
require.Equal(t, block.MerkleRoot.BytesLE(), value)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeaderGetNextConsensus(t *testing.T) {
|
|
|
|
v, block, context := createVMAndPushBlock(t)
|
|
|
|
|
|
|
|
err := context.headerGetNextConsensus(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value()
|
2019-11-27 09:20:31 +00:00
|
|
|
require.Equal(t, block.NextConsensus.BytesLE(), value)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTxGetAttributes(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndPushTX(t)
|
|
|
|
|
|
|
|
err := context.txGetAttributes(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().([]vm.StackItem)
|
|
|
|
require.Equal(t, tx.Attributes[0].Usage, value[0].Value().(*transaction.Attribute).Usage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTxGetInputs(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndPushTX(t)
|
|
|
|
|
|
|
|
err := context.txGetInputs(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().([]vm.StackItem)
|
2019-12-09 14:14:10 +00:00
|
|
|
require.Equal(t, tx.Inputs[0], *value[0].Value().(*transaction.Input))
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTxGetOutputs(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndPushTX(t)
|
|
|
|
|
|
|
|
err := context.txGetOutputs(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().([]vm.StackItem)
|
2019-12-09 14:14:10 +00:00
|
|
|
require.Equal(t, tx.Outputs[0], *value[0].Value().(*transaction.Output))
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTxGetType(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndPushTX(t)
|
|
|
|
|
|
|
|
err := context.txGetType(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
value := v.Estack().Pop().Value().(*big.Int)
|
|
|
|
require.Equal(t, big.NewInt(int64(tx.Type)), value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPopInputFromVM(t *testing.T) {
|
|
|
|
v, tx, _ := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
input, err := popInputFromVM(v)
|
|
|
|
require.NoError(t, err)
|
2019-12-09 14:14:10 +00:00
|
|
|
require.Equal(t, tx.Inputs[0], *input)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInputGetHash(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.inputGetHash(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
hash := v.Estack().Pop().Value()
|
2019-11-27 09:23:18 +00:00
|
|
|
require.Equal(t, tx.Inputs[0].PrevHash.BytesBE(), hash)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInputGetIndex(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Inputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.inputGetIndex(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
index := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(tx.Inputs[0].PrevIndex)), index)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPopOutputFromVM(t *testing.T) {
|
|
|
|
v, tx, _ := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
output, err := popOutputFromVM(v)
|
|
|
|
require.NoError(t, err)
|
2019-12-09 14:14:10 +00:00
|
|
|
require.Equal(t, tx.Outputs[0], *output)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputGetAssetID(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.outputGetAssetID(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assetID := v.Estack().Pop().Value()
|
2019-11-27 09:23:18 +00:00
|
|
|
require.Equal(t, tx.Outputs[0].AssetID.BytesBE(), assetID)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputGetScriptHash(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.outputGetScriptHash(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
scriptHash := v.Estack().Pop().Value()
|
2019-11-27 09:20:31 +00:00
|
|
|
require.Equal(t, tx.Outputs[0].ScriptHash.BytesBE(), scriptHash)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputGetValue(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Outputs[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.outputGetValue(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
amount := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(tx.Outputs[0].Amount)), amount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAttrGetData(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Attributes[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.attrGetData(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
data := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, tx.Attributes[0].Data, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAttrGetUsage(t *testing.T) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
2019-12-09 14:14:10 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(&tx.Attributes[0]))
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
err := context.attrGetUsage(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
usage := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(tx.Attributes[0].Usage)), usage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccountGetScriptHash(t *testing.T) {
|
|
|
|
v, accState, context := createVMAndAccState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(accState))
|
|
|
|
|
|
|
|
err := context.accountGetScriptHash(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
hash := v.Estack().Pop().Value()
|
2019-11-27 09:20:31 +00:00
|
|
|
require.Equal(t, accState.ScriptHash.BytesBE(), hash)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccountGetVotes(t *testing.T) {
|
|
|
|
v, accState, context := createVMAndAccState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(accState))
|
|
|
|
|
|
|
|
err := context.accountGetVotes(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
votes := v.Estack().Pop().Value().([]vm.StackItem)
|
|
|
|
require.Equal(t, vm.NewByteArrayItem(accState.Votes[0].Bytes()), votes[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContractGetScript(t *testing.T) {
|
|
|
|
v, contractState, context := createVMAndContractState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(contractState))
|
|
|
|
|
|
|
|
err := context.contractGetScript(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
script := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, contractState.Script, script)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContractIsPayable(t *testing.T) {
|
|
|
|
v, contractState, context := createVMAndContractState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(contractState))
|
|
|
|
|
|
|
|
err := context.contractIsPayable(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
isPayable := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, contractState.IsPayable(), isPayable)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetAdmin(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetAdmin(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
admin := v.Estack().Pop().Value()
|
2019-11-27 09:20:31 +00:00
|
|
|
require.Equal(t, assetState.Admin.BytesBE(), admin)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetAmount(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetAmount(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
amount := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(assetState.Amount)), amount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetAssetID(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetAssetID(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assetID := v.Estack().Pop().Value()
|
2019-11-27 09:23:18 +00:00
|
|
|
require.Equal(t, assetState.ID.BytesBE(), assetID)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetAssetType(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetAssetType(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assetType := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(assetState.AssetType)), assetType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetAvailable(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetAvailable(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
available := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(assetState.Available)), available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetIssuer(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetIssuer(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
issuer := v.Estack().Pop().Value()
|
2019-11-27 09:20:31 +00:00
|
|
|
require.Equal(t, assetState.Issuer.BytesBE(), issuer)
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetOwner(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetOwner(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
owner := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, assetState.Owner.Bytes(), owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssetGetPrecision(t *testing.T) {
|
|
|
|
v, assetState, context := createVMAndAssetState(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(assetState))
|
|
|
|
|
|
|
|
err := context.assetGetPrecision(v)
|
|
|
|
require.NoError(t, err)
|
|
|
|
precision := v.Estack().Pop().Value()
|
|
|
|
require.Equal(t, big.NewInt(int64(assetState.Precision)), precision)
|
|
|
|
}
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
// Helper functions to create VM, InteropContext, TX, Account, Contract, Asset.
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
func createVMAndPushBlock(t *testing.T) (*vm.VM, *Block, *interopContext) {
|
|
|
|
v := vm.New()
|
|
|
|
block := newDumbBlock()
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), block, nil)
|
2019-11-18 16:31:27 +00:00
|
|
|
v.Estack().PushVal(vm.NewInteropItem(block))
|
|
|
|
return v, block, context
|
|
|
|
}
|
|
|
|
|
|
|
|
func createVMAndPushTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interopContext) {
|
|
|
|
v, tx, context := createVMAndTX(t)
|
|
|
|
v.Estack().PushVal(vm.NewInteropItem(tx))
|
|
|
|
return v, tx, context
|
|
|
|
}
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
func createVMAndAssetState(t *testing.T) (*vm.VM, *state.Asset, *interopContext) {
|
2019-11-18 16:31:27 +00:00
|
|
|
v := vm.New()
|
2019-11-28 16:06:09 +00:00
|
|
|
assetState := &state.Asset{
|
2019-11-18 16:31:27 +00:00
|
|
|
ID: util.Uint256{},
|
|
|
|
AssetType: transaction.GoverningToken,
|
|
|
|
Name: "TestAsset",
|
|
|
|
Amount: 1,
|
|
|
|
Available: 2,
|
|
|
|
Precision: 1,
|
|
|
|
FeeMode: 1,
|
2019-12-04 12:24:49 +00:00
|
|
|
FeeAddress: random.Uint160(),
|
2019-12-09 15:33:04 +00:00
|
|
|
Owner: keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)},
|
2019-12-04 12:24:49 +00:00
|
|
|
Admin: random.Uint160(),
|
|
|
|
Issuer: random.Uint160(),
|
2019-11-18 16:31:27 +00:00
|
|
|
Expiration: 10,
|
|
|
|
IsFrozen: false,
|
|
|
|
}
|
|
|
|
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), nil, nil)
|
2019-11-18 16:31:27 +00:00
|
|
|
return v, assetState, context
|
|
|
|
}
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
func createVMAndContractState(t *testing.T) (*vm.VM, *state.Contract, *interopContext) {
|
2019-11-18 16:31:27 +00:00
|
|
|
v := vm.New()
|
2019-11-28 16:06:09 +00:00
|
|
|
contractState := &state.Contract{
|
2019-11-18 16:31:27 +00:00
|
|
|
Script: []byte("testscript"),
|
|
|
|
ParamList: []smartcontract.ParamType{smartcontract.StringType, smartcontract.IntegerType, smartcontract.Hash160Type},
|
|
|
|
ReturnType: smartcontract.ArrayType,
|
|
|
|
Properties: smartcontract.HasStorage,
|
2019-12-04 12:24:49 +00:00
|
|
|
Name: random.String(10),
|
|
|
|
CodeVersion: random.String(10),
|
|
|
|
Author: random.String(10),
|
|
|
|
Email: random.String(10),
|
|
|
|
Description: random.String(10),
|
2019-11-18 16:31:27 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), nil, nil)
|
2019-11-18 16:31:27 +00:00
|
|
|
return v, contractState, context
|
|
|
|
}
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
func createVMAndAccState(t *testing.T) (*vm.VM, *state.Account, *interopContext) {
|
2019-11-18 16:31:27 +00:00
|
|
|
v := vm.New()
|
|
|
|
rawHash := "4d3b96ae1bcc5a585e075e3b81920210dec16302"
|
2019-11-27 09:20:31 +00:00
|
|
|
hash, err := util.Uint160DecodeStringBE(rawHash)
|
2019-11-28 16:06:09 +00:00
|
|
|
accountState := state.NewAccount(hash)
|
2019-11-18 16:31:27 +00:00
|
|
|
|
|
|
|
key := &keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)}
|
|
|
|
accountState.Votes = []*keys.PublicKey{key}
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), nil, nil)
|
2019-11-18 16:31:27 +00:00
|
|
|
return v, accountState, context
|
|
|
|
}
|
|
|
|
|
|
|
|
func createVMAndTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interopContext) {
|
|
|
|
v := vm.New()
|
|
|
|
tx := newMinerTX()
|
|
|
|
|
|
|
|
bytes := make([]byte, 1)
|
2019-12-09 14:14:10 +00:00
|
|
|
attributes := append(tx.Attributes, transaction.Attribute{
|
2019-11-18 16:31:27 +00:00
|
|
|
Usage: transaction.Description,
|
|
|
|
Data: bytes,
|
|
|
|
})
|
|
|
|
|
2019-12-09 14:14:10 +00:00
|
|
|
inputs := append(tx.Inputs, transaction.Input{
|
2019-12-04 12:24:49 +00:00
|
|
|
PrevHash: random.Uint256(),
|
2019-11-18 16:31:27 +00:00
|
|
|
PrevIndex: 1,
|
|
|
|
})
|
|
|
|
|
2019-12-09 14:14:10 +00:00
|
|
|
outputs := append(tx.Outputs, transaction.Output{
|
2019-12-04 12:24:49 +00:00
|
|
|
AssetID: random.Uint256(),
|
2019-11-18 16:31:27 +00:00
|
|
|
Amount: 10,
|
2019-12-04 12:24:49 +00:00
|
|
|
ScriptHash: random.Uint160(),
|
2019-11-18 16:31:27 +00:00
|
|
|
Position: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
tx.Attributes = attributes
|
|
|
|
tx.Inputs = inputs
|
|
|
|
tx.Outputs = outputs
|
2019-12-04 09:27:04 +00:00
|
|
|
context := newInteropContext(trigger.Application, newTestChain(t), storage.NewMemoryStore(), nil, tx)
|
2019-11-18 16:31:27 +00:00
|
|
|
return v, tx, context
|
|
|
|
}
|