mirror of https://github.com/poanetwork/gecko.git
merged
This commit is contained in:
commit
1dc6fb77b9
23
node/node.go
23
node/node.go
|
@ -4,7 +4,7 @@
|
|||
package node
|
||||
|
||||
// #include "salticidae/network.h"
|
||||
// void onTerm(int sig, void *);
|
||||
// void onTerm(threadcall_handle_t *, void *);
|
||||
// void errorHandler(SalticidaeCError *, bool, int32_t, void *);
|
||||
import "C"
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
@ -35,6 +36,7 @@ import (
|
|||
"github.com/ava-labs/gecko/networking/xputtest"
|
||||
"github.com/ava-labs/gecko/snow/triggers"
|
||||
"github.com/ava-labs/gecko/snow/validators"
|
||||
"github.com/ava-labs/gecko/utils"
|
||||
"github.com/ava-labs/gecko/utils/hashing"
|
||||
"github.com/ava-labs/gecko/utils/logging"
|
||||
"github.com/ava-labs/gecko/utils/wrappers"
|
||||
|
@ -92,6 +94,10 @@ type Node struct {
|
|||
|
||||
// Event loop manager
|
||||
EC salticidae.EventContext
|
||||
|
||||
// Caller to the event context
|
||||
TCall salticidae.ThreadCall
|
||||
|
||||
// Network that manages validator peers
|
||||
PeerNet salticidae.PeerNetwork
|
||||
// Network that manages clients
|
||||
|
@ -115,6 +121,9 @@ type Node struct {
|
|||
|
||||
// This node's configuration
|
||||
Config *Config
|
||||
|
||||
// channel for closing the node
|
||||
nodeCloser chan<- os.Signal
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -124,7 +133,7 @@ type Node struct {
|
|||
*/
|
||||
|
||||
//export onTerm
|
||||
func onTerm(C.int, unsafe.Pointer) {
|
||||
func onTerm(*C.threadcall_handle_t, unsafe.Pointer) {
|
||||
MainNode.Log.Debug("Terminate signal received")
|
||||
MainNode.EC.Stop()
|
||||
}
|
||||
|
@ -143,12 +152,11 @@ func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, asyncID C.int32
|
|||
func (n *Node) initNetlib() error {
|
||||
// Create main event context
|
||||
n.EC = salticidae.NewEventContext()
|
||||
n.TCall = salticidae.NewThreadCall(n.EC)
|
||||
|
||||
// Set up interrupt signal and terminate signal handlers
|
||||
evInt := salticidae.NewSigEvent(n.EC, salticidae.SigEventCallback(C.onTerm), nil)
|
||||
evInt.Add(salticidae.SIGINT)
|
||||
evTerm := salticidae.NewSigEvent(n.EC, salticidae.SigEventCallback(C.onTerm), nil)
|
||||
evTerm.Add(salticidae.SIGTERM)
|
||||
n.nodeCloser = utils.HandleSignals(func(os.Signal) {
|
||||
n.TCall.AsyncCall(salticidae.ThreadCallCallback(C.onTerm), nil)
|
||||
}, os.Interrupt, os.Kill)
|
||||
|
||||
// Create peer network config, may have tls enabled
|
||||
peerConfig := salticidae.NewPeerNetworkConfig()
|
||||
|
@ -655,4 +663,5 @@ func (n *Node) Shutdown() {
|
|||
n.ValidatorAPI.Shutdown()
|
||||
n.ConsensusAPI.Shutdown()
|
||||
n.chainManager.Shutdown()
|
||||
utils.ClearSignals(n.nodeCloser)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
- name: Kill Node
|
||||
command: killall ava
|
||||
command: killall -SIGINT ava
|
||||
ignore_errors: true
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
SRC_DIR="$(dirname "${BASH_SOURCE[0]}")"
|
||||
source "$SRC_DIR/env.sh"
|
||||
|
||||
go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
||||
go test -race -timeout="30s" -coverprofile="coverage.out" -covermode="atomic" ./...
|
||||
|
|
|
@ -50,3 +50,10 @@ func (r *request) Method() (string, error) {
|
|||
uppercaseRune := string(unicode.ToUpper(firstRune))
|
||||
return fmt.Sprintf("%s.%s%s", class, string(uppercaseRune), function[runeLen:]), nil
|
||||
}
|
||||
|
||||
func (r *request) ReadRequest(args interface{}) error {
|
||||
if err := r.CodecRequest.ReadRequest(args); err != nil {
|
||||
return errors.New("couldn't unmarshal an argument. Ensure arguments are valid and properly formatted. See documentation for example calls")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
)
|
||||
|
||||
// HandleSignals calls f if the go runtime receives the any of the provided
|
||||
// signals with the received signal.
|
||||
//
|
||||
// If f is nil or there are no provided signals, then nil will be returned.
|
||||
// Otherwise, a signal channel will be returned that can be used to clear the
|
||||
// signals registed by this function by valling ClearSignals.
|
||||
func HandleSignals(f func(os.Signal), sigs ...os.Signal) chan<- os.Signal {
|
||||
if f == nil || len(sigs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// register signals
|
||||
c := make(chan os.Signal, 1)
|
||||
for _, sig := range sigs {
|
||||
signal.Notify(c, sig)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for sig := range c {
|
||||
f(sig)
|
||||
}
|
||||
}()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// ClearSignals clears any signals that have been registered on the provided
|
||||
// channel and closes the channel.
|
||||
func ClearSignals(c chan<- os.Signal) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
|
||||
signal.Stop(c)
|
||||
close(c)
|
||||
}
|
|
@ -623,7 +623,10 @@ func TestBaseTxSyntacticVerifyUninitialized(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerify(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -687,7 +690,10 @@ func TestBaseTxSemanticVerify(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.codec.RegisterType(&ava.TestVerifiable{})
|
||||
|
||||
|
@ -736,7 +742,10 @@ func TestBaseTxSemanticVerifyUnknownFx(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerifyWrongAssetID(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.codec.RegisterType(&ava.TestVerifiable{})
|
||||
|
||||
|
@ -801,14 +810,15 @@ func TestBaseTxSemanticVerifyWrongAssetID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
issuer := make(chan common.Message, 1)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
issuer := make(chan common.Message, 1)
|
||||
err := vm.Initialize(
|
||||
ctx,
|
||||
memdb.New(),
|
||||
|
@ -893,7 +903,10 @@ func TestBaseTxSemanticVerifyUnauthorizedFx(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -944,7 +957,10 @@ func TestBaseTxSemanticVerifyInvalidSignature(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -1008,7 +1024,10 @@ func TestBaseTxSemanticVerifyMissingUTXO(t *testing.T) {
|
|||
|
||||
func TestBaseTxSemanticVerifyInvalidUTXO(t *testing.T) {
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -1140,7 +1159,10 @@ func TestBaseTxSemanticVerifyPendingInvalidUTXO(t *testing.T) {
|
|||
<-issuer
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.PendingTxs()
|
||||
|
||||
|
@ -1271,7 +1293,10 @@ func TestBaseTxSemanticVerifyPendingWrongAssetID(t *testing.T) {
|
|||
<-issuer
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.PendingTxs()
|
||||
|
||||
|
@ -1436,7 +1461,10 @@ func TestBaseTxSemanticVerifyPendingUnauthorizedFx(t *testing.T) {
|
|||
<-issuer
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.PendingTxs()
|
||||
|
||||
|
@ -1585,7 +1613,10 @@ func TestBaseTxSemanticVerifyPendingInvalidSignature(t *testing.T) {
|
|||
<-issuer
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
vm.PendingTxs()
|
||||
|
||||
|
|
|
@ -216,7 +216,10 @@ func TestIssueExportTx(t *testing.T) {
|
|||
}
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txs := vm.PendingTxs()
|
||||
if len(txs) != 1 {
|
||||
|
@ -349,7 +352,10 @@ func TestClearForceAcceptedExportTx(t *testing.T) {
|
|||
}
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txs := vm.PendingTxs()
|
||||
if len(txs) != 1 {
|
||||
|
|
|
@ -220,7 +220,6 @@ func TestIssueImportTx(t *testing.T) {
|
|||
if _, err := vm.IssueTx(tx.Bytes(), nil); err != nil {
|
||||
t.Fatalf("should have issued the transaction correctly but errored: %s", err)
|
||||
}
|
||||
|
||||
ctx.Lock.Unlock()
|
||||
|
||||
msg := <-issuer
|
||||
|
@ -228,6 +227,12 @@ func TestIssueImportTx(t *testing.T) {
|
|||
t.Fatalf("Wrong message")
|
||||
}
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txs := vm.PendingTxs()
|
||||
if len(txs) != 1 {
|
||||
t.Fatalf("Should have returned %d tx(s)", 1)
|
||||
|
@ -261,10 +266,13 @@ func TestForceAcceptImportTx(t *testing.T) {
|
|||
|
||||
platformID := ids.Empty.Prefix(0)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{platform: platformID}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
err := vm.Initialize(
|
||||
ctx,
|
||||
memdb.New(),
|
||||
|
|
|
@ -17,7 +17,11 @@ import (
|
|||
|
||||
func TestPrefixedSetsAndGets(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state
|
||||
|
||||
vm.codec.RegisterType(&ava.TestVerifiable{})
|
||||
|
@ -112,7 +116,11 @@ func TestPrefixedSetsAndGets(t *testing.T) {
|
|||
|
||||
func TestPrefixedFundingNoAddresses(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state
|
||||
|
||||
vm.codec.RegisterType(&ava.TestVerifiable{})
|
||||
|
@ -136,7 +144,11 @@ func TestPrefixedFundingNoAddresses(t *testing.T) {
|
|||
|
||||
func TestPrefixedFundingAddresses(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state
|
||||
|
||||
vm.codec.RegisterType(&testAddressable{})
|
||||
|
|
|
@ -9,45 +9,23 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/ava-labs/gecko/database/memdb"
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/snow/choices"
|
||||
"github.com/ava-labs/gecko/snow/engine/common"
|
||||
"github.com/ava-labs/gecko/utils/formatting"
|
||||
"github.com/ava-labs/gecko/vms/secp256k1fx"
|
||||
)
|
||||
|
||||
func setup(t *testing.T) ([]byte, *VM, *Service) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
|
||||
// This VM initilialzation is very similar to that done by GenesisVM().
|
||||
// However replacing the body of this function, with a call to GenesisVM
|
||||
// causes a timeout while executing the test suite.
|
||||
// https://github.com/ava-labs/gecko/pull/59#pullrequestreview-392478636
|
||||
vm := &VM{}
|
||||
err := vm.Initialize(
|
||||
ctx,
|
||||
memdb.New(),
|
||||
genesisBytes,
|
||||
make(chan common.Message, 1),
|
||||
[]*common.Fx{&common.Fx{
|
||||
ID: ids.Empty,
|
||||
Fx: &secp256k1fx.Fx{},
|
||||
}},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
genesisBytes, _, vm := GenesisVM(t)
|
||||
s := &Service{vm: vm}
|
||||
return genesisBytes, vm, s
|
||||
}
|
||||
|
||||
func TestServiceIssueTx(t *testing.T) {
|
||||
genesisBytes, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txArgs := &IssueTxArgs{}
|
||||
txReply := &IssueTxReply{}
|
||||
|
@ -69,8 +47,10 @@ func TestServiceIssueTx(t *testing.T) {
|
|||
|
||||
func TestServiceGetTxStatus(t *testing.T) {
|
||||
genesisBytes, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
statusArgs := &GetTxStatusArgs{}
|
||||
statusReply := &GetTxStatusReply{}
|
||||
|
@ -110,8 +90,10 @@ func TestServiceGetTxStatus(t *testing.T) {
|
|||
|
||||
func TestServiceGetTx(t *testing.T) {
|
||||
genesisBytes, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
genesisTxBytes := genesisTx.Bytes()
|
||||
|
@ -127,8 +109,10 @@ func TestServiceGetTx(t *testing.T) {
|
|||
|
||||
func TestServiceGetNilTx(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
reply := GetTxReply{}
|
||||
err := s.GetTx(nil, &GetTxArgs{}, &reply)
|
||||
|
@ -137,8 +121,10 @@ func TestServiceGetNilTx(t *testing.T) {
|
|||
|
||||
func TestServiceGetUnknownTx(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
reply := GetTxReply{}
|
||||
err := s.GetTx(nil, &GetTxArgs{TxID: ids.Empty}, &reply)
|
||||
|
@ -147,8 +133,10 @@ func TestServiceGetUnknownTx(t *testing.T) {
|
|||
|
||||
func TestServiceGetUTXOsInvalidAddress(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
addr0 := keys[0].PublicKey().Address()
|
||||
tests := []struct {
|
||||
|
@ -175,8 +163,10 @@ func TestServiceGetUTXOsInvalidAddress(t *testing.T) {
|
|||
|
||||
func TestServiceGetUTXOs(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
addr0 := keys[0].PublicKey().Address()
|
||||
tests := []struct {
|
||||
|
@ -225,8 +215,10 @@ func TestServiceGetUTXOs(t *testing.T) {
|
|||
|
||||
func TestGetAssetDescription(t *testing.T) {
|
||||
genesisBytes, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -250,8 +242,10 @@ func TestGetAssetDescription(t *testing.T) {
|
|||
|
||||
func TestGetBalance(t *testing.T) {
|
||||
genesisBytes, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -273,8 +267,10 @@ func TestGetBalance(t *testing.T) {
|
|||
|
||||
func TestCreateFixedCapAsset(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
reply := CreateFixedCapAssetReply{}
|
||||
err := s.CreateFixedCapAsset(nil, &CreateFixedCapAssetArgs{
|
||||
|
@ -297,8 +293,10 @@ func TestCreateFixedCapAsset(t *testing.T) {
|
|||
|
||||
func TestCreateVariableCapAsset(t *testing.T) {
|
||||
_, vm, s := setup(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
reply := CreateVariableCapAssetReply{}
|
||||
err := s.CreateVariableCapAsset(nil, &CreateVariableCapAssetArgs{
|
||||
|
|
|
@ -16,7 +16,11 @@ import (
|
|||
|
||||
func TestStateIDs(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state.state
|
||||
|
||||
id0 := ids.NewID([32]byte{0xff, 0})
|
||||
|
@ -126,7 +130,11 @@ func TestStateIDs(t *testing.T) {
|
|||
|
||||
func TestStateStatuses(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state.state
|
||||
|
||||
if _, err := state.Status(ids.Empty); err == nil {
|
||||
|
@ -175,7 +183,11 @@ func TestStateStatuses(t *testing.T) {
|
|||
|
||||
func TestStateUTXOs(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state.state
|
||||
|
||||
vm.codec.RegisterType(&ava.TestVerifiable{})
|
||||
|
@ -246,7 +258,11 @@ func TestStateUTXOs(t *testing.T) {
|
|||
|
||||
func TestStateTXs(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
ctx.Lock.Unlock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
state := vm.state.state
|
||||
|
||||
vm.codec.RegisterType(&ava.TestTransferable{})
|
||||
|
|
|
@ -204,7 +204,12 @@ func (vm *VM) Shutdown() {
|
|||
return
|
||||
}
|
||||
|
||||
// There is a potential deadlock if the timer is about to execute a timeout.
|
||||
// So, the lock must be released before stopping the timer.
|
||||
vm.ctx.Lock.Unlock()
|
||||
vm.timer.Stop()
|
||||
vm.ctx.Lock.Lock()
|
||||
|
||||
if err := vm.baseDB.Close(); err != nil {
|
||||
vm.ctx.Log.Error("Closing the database failed with %s", err)
|
||||
}
|
||||
|
|
|
@ -392,10 +392,13 @@ func TestTxSerialization(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvalidGenesis(t *testing.T) {
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
err := vm.Initialize(
|
||||
/*context=*/ ctx,
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -409,12 +412,14 @@ func TestInvalidGenesis(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvalidFx(t *testing.T) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
err := vm.Initialize(
|
||||
/*context=*/ ctx,
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -430,12 +435,14 @@ func TestInvalidFx(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFxInitializationFailure(t *testing.T) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
err := vm.Initialize(
|
||||
/*context=*/ ctx,
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -457,6 +464,10 @@ func (tx *testTxBytes) UnsignedBytes() []byte { return tx.unsignedBytes }
|
|||
|
||||
func TestIssueTx(t *testing.T) {
|
||||
genesisBytes, issuer, vm := GenesisVM(t)
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
newTx := NewTx(t, genesisBytes, vm)
|
||||
|
||||
|
@ -473,6 +484,7 @@ func TestIssueTx(t *testing.T) {
|
|||
if msg != common.PendingTxs {
|
||||
t.Fatalf("Wrong message")
|
||||
}
|
||||
ctx.Lock.Lock()
|
||||
|
||||
if txs := vm.PendingTxs(); len(txs) != 1 {
|
||||
t.Fatalf("Should have returned %d tx(s)", 1)
|
||||
|
@ -481,6 +493,10 @@ func TestIssueTx(t *testing.T) {
|
|||
|
||||
func TestGenesisGetUTXOs(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
shortAddr := keys[0].PublicKey().Address()
|
||||
addr := ids.NewID(hashing.ComputeHash256Array(shortAddr.Bytes()))
|
||||
|
@ -491,8 +507,6 @@ func TestGenesisGetUTXOs(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
|
||||
if len(utxos) != 7 {
|
||||
t.Fatalf("Wrong number of utxos. Expected (%d) returned (%d)", 7, len(utxos))
|
||||
|
@ -503,6 +517,10 @@ func TestGenesisGetUTXOs(t *testing.T) {
|
|||
// transaction should be issued successfully.
|
||||
func TestIssueDependentTx(t *testing.T) {
|
||||
genesisBytes, issuer, vm := GenesisVM(t)
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisTx := GetFirstTxFromGenesisTest(genesisBytes, t)
|
||||
|
||||
|
@ -615,13 +633,13 @@ func TestIssueDependentTx(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx.Lock.Unlock()
|
||||
|
||||
msg := <-issuer
|
||||
if msg != common.PendingTxs {
|
||||
t.Fatalf("Wrong message")
|
||||
}
|
||||
ctx.Lock.Lock()
|
||||
|
||||
if txs := vm.PendingTxs(); len(txs) != 2 {
|
||||
t.Fatalf("Should have returned %d tx(s)", 2)
|
||||
|
@ -630,14 +648,15 @@ func TestIssueDependentTx(t *testing.T) {
|
|||
|
||||
// Test issuing a transaction that creates an NFT family
|
||||
func TestIssueNFT(t *testing.T) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
issuer := make(chan common.Message, 1)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
issuer := make(chan common.Message, 1)
|
||||
err := vm.Initialize(
|
||||
ctx,
|
||||
memdb.New(),
|
||||
|
@ -788,14 +807,15 @@ func TestIssueNFT(t *testing.T) {
|
|||
|
||||
// Test issuing a transaction that creates an Property family
|
||||
func TestIssueProperty(t *testing.T) {
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
|
||||
issuer := make(chan common.Message, 1)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
|
||||
vm := &VM{}
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
genesisBytes := BuildGenesisTest(t)
|
||||
issuer := make(chan common.Message, 1)
|
||||
err := vm.Initialize(
|
||||
ctx,
|
||||
memdb.New(),
|
||||
|
@ -937,8 +957,10 @@ func TestIssueProperty(t *testing.T) {
|
|||
|
||||
func TestVMFormat(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tests := []struct {
|
||||
in string
|
||||
|
@ -957,8 +979,10 @@ func TestVMFormat(t *testing.T) {
|
|||
|
||||
func TestVMFormatAliased(t *testing.T) {
|
||||
_, _, vm := GenesisVM(t)
|
||||
defer ctx.Lock.Unlock()
|
||||
defer vm.Shutdown()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
origAliases := ctx.BCLookup
|
||||
defer func() { ctx.BCLookup = origAliases }()
|
||||
|
|
|
@ -13,6 +13,11 @@ import (
|
|||
|
||||
func TestAddDefaultSubnetDelegatorTxSyntacticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: tx is nil
|
||||
var tx *addDefaultSubnetDelegatorTx
|
||||
|
@ -153,6 +158,11 @@ func TestAddDefaultSubnetDelegatorTxSyntacticVerify(t *testing.T) {
|
|||
|
||||
func TestAddDefaultSubnetDelegatorTxSemanticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: Proposed validator currently validating default subnet
|
||||
// but stops validating non-default subnet after stops validating default subnet
|
||||
|
|
|
@ -12,6 +12,11 @@ import (
|
|||
|
||||
func TestAddDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: tx is nil
|
||||
var tx *addDefaultSubnetValidatorTx
|
||||
|
@ -216,6 +221,11 @@ func TestAddDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
// Test AddDefaultSubnetValidatorTx.SemanticVerify
|
||||
func TestAddDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: Validator's start time too early
|
||||
tx, err := vm.newAddDefaultSubnetValidatorTx(
|
||||
|
@ -281,9 +291,9 @@ func TestAddDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
}
|
||||
startTime := defaultGenesisTime.Add(1 * time.Second)
|
||||
tx, err = vm.newAddDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultStakeAmount, // stake amount
|
||||
uint64(startTime.Unix()), // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultStakeAmount, // stake amount
|
||||
uint64(startTime.Unix()), // start time
|
||||
uint64(startTime.Add(MinimumStakingDuration).Unix()), // end time
|
||||
key.PublicKey().Address(), // node ID
|
||||
defaultKey.PublicKey().Address(), // destination
|
||||
|
|
|
@ -14,6 +14,11 @@ import (
|
|||
|
||||
func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: tx is nil
|
||||
var tx *addNonDefaultSubnetValidatorTx
|
||||
|
@ -202,6 +207,11 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
|
||||
func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: Proposed validator currently validating default subnet
|
||||
// but stops validating non-default subnet after stops validating default subnet
|
||||
|
@ -590,12 +600,16 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("should have failed verification because validator already in pending validator set of the specified subnet")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test that marshalling/unmarshalling works
|
||||
func TestAddNonDefaultSubnetValidatorMarshal(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// valid tx
|
||||
tx, err := vm.newAddNonDefaultSubnetValidatorTx(
|
||||
|
|
|
@ -17,6 +17,12 @@ func TestAdvanceTimeTxSyntacticVerify(t *testing.T) {
|
|||
|
||||
// Case 2: Timestamp is ahead of synchrony bound
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tx = &advanceTimeTx{
|
||||
Time: uint64(defaultGenesisTime.Add(Delta).Add(1 * time.Second).Unix()),
|
||||
vm: vm,
|
||||
|
@ -38,6 +44,11 @@ func TestAdvanceTimeTxSyntacticVerify(t *testing.T) {
|
|||
// Ensure semantic verification fails when proposed timestamp is at or before current timestamp
|
||||
func TestAdvanceTimeTxTimestampTooEarly(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tx := &advanceTimeTx{
|
||||
Time: uint64(defaultGenesisTime.Unix()),
|
||||
|
@ -52,6 +63,7 @@ func TestAdvanceTimeTxTimestampTooEarly(t *testing.T) {
|
|||
// Ensure semantic verification fails when proposed timestamp is after next validator set change time
|
||||
func TestAdvanceTimeTxTimestampTooLate(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
|
||||
// Case 1: Timestamp is after next validator start time
|
||||
// Add a pending validator
|
||||
|
@ -94,9 +106,16 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("should've failed verification because proposed timestamp is after pending validator start time")
|
||||
}
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Case 2: Timestamp is after next validator end time
|
||||
vm = defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// fast forward clock to 10 seconds before genesis validators stop validating
|
||||
vm.clock.Set(defaultValidateEndTime.Add(-10 * time.Second))
|
||||
|
@ -117,6 +136,11 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) {
|
|||
// Ensure semantic verification updates the current and pending validator sets correctly
|
||||
func TestAdvanceTimeTxUpdateValidators(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: Timestamp is after next validator start time
|
||||
// Add a pending validator
|
||||
|
@ -196,6 +220,11 @@ func TestAdvanceTimeTxUpdateValidators(t *testing.T) {
|
|||
// Test method InitiallyPrefersCommit
|
||||
func TestAdvanceTimeTxInitiallyPrefersCommit(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Proposed advancing timestamp to 1 second after current timestamp
|
||||
tx, err := vm.newAdvanceTimeTx(defaultGenesisTime.Add(1 * time.Second))
|
||||
|
@ -217,6 +246,11 @@ func TestAdvanceTimeTxInitiallyPrefersCommit(t *testing.T) {
|
|||
// Ensure marshaling/unmarshaling works
|
||||
func TestAdvanceTimeTxUnmarshal(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tx, err := vm.newAdvanceTimeTx(defaultGenesisTime)
|
||||
if err != nil {
|
||||
|
|
|
@ -14,6 +14,11 @@ import (
|
|||
// test method SyntacticVerify
|
||||
func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: tx is nil
|
||||
var tx *CreateChainTx
|
||||
|
@ -142,6 +147,11 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Ensure SemanticVerify fails when there are not enough control sigs
|
||||
func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Case 1: No control sigs (2 are needed)
|
||||
tx, err := vm.newCreateChainTx(
|
||||
|
@ -189,6 +199,11 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
|
|||
// Ensure SemanticVerify fails when an incorrect control signature is given
|
||||
func TestCreateChainTxWrongControlSig(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Generate new, random key to sign tx with
|
||||
factory := crypto.FactorySECP256K1R{}
|
||||
|
@ -222,6 +237,11 @@ func TestCreateChainTxWrongControlSig(t *testing.T) {
|
|||
// its validator set doesn't exist
|
||||
func TestCreateChainTxNoSuchSubnet(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
|
@ -245,6 +265,11 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) {
|
|||
|
||||
func TestCreateChainTxAlreadyExists(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// create a tx
|
||||
tx, err := vm.newCreateChainTx(
|
||||
|
@ -276,6 +301,11 @@ func TestCreateChainTxAlreadyExists(t *testing.T) {
|
|||
// Ensure valid tx passes semanticVerify
|
||||
func TestCreateChainTxValid(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// create a valid tx
|
||||
tx, err := vm.newCreateChainTx(
|
||||
|
|
|
@ -11,6 +11,12 @@ import (
|
|||
|
||||
func TestTxHeapStart(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txHeap := EventHeap{SortByStartTime: true}
|
||||
|
||||
validator0, err := vm.newAddDefaultSubnetValidatorTx(
|
||||
|
@ -78,6 +84,12 @@ func TestTxHeapStart(t *testing.T) {
|
|||
|
||||
func TestTxHeapStop(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txHeap := EventHeap{}
|
||||
|
||||
validator0, err := vm.newAddDefaultSubnetValidatorTx(
|
||||
|
@ -145,6 +157,12 @@ func TestTxHeapStop(t *testing.T) {
|
|||
|
||||
func TestTxHeapStartValidatorVsDelegatorOrdering(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txHeap := EventHeap{SortByStartTime: true}
|
||||
|
||||
validator, err := vm.newAddDefaultSubnetValidatorTx(
|
||||
|
@ -186,6 +204,12 @@ func TestTxHeapStartValidatorVsDelegatorOrdering(t *testing.T) {
|
|||
|
||||
func TestTxHeapStopValidatorVsDelegatorOrdering(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txHeap := EventHeap{}
|
||||
|
||||
validator, err := vm.newAddDefaultSubnetValidatorTx(
|
||||
|
|
|
@ -18,6 +18,12 @@ func TestRewardValidatorTxSyntacticVerify(t *testing.T) {
|
|||
}
|
||||
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
txID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7})
|
||||
|
||||
tests := []test{
|
||||
|
@ -54,6 +60,12 @@ func TestRewardValidatorTxSyntacticVerify(t *testing.T) {
|
|||
|
||||
func TestRewardValidatorTxSemanticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
var nextToRemove *addDefaultSubnetValidatorTx
|
||||
currentValidators, err := vm.getCurrentValidators(vm.DB, DefaultSubnetID)
|
||||
if err != nil {
|
||||
|
@ -130,6 +142,11 @@ func TestRewardValidatorTxSemanticVerify(t *testing.T) {
|
|||
|
||||
func TestRewardDelegatorTxSemanticVerify(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
keyIntf1, err := vm.factory.NewPrivateKey()
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/ava-labs/gecko/database"
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
|
@ -34,6 +35,8 @@ var (
|
|||
errGetStakeSource = errors.New("couldn't get account specified in 'stakeSource'")
|
||||
errNoBlockchainWithAlias = errors.New("there is no blockchain with the specified alias")
|
||||
errDSCantValidate = errors.New("new blockchain can't be validated by default Subnet")
|
||||
errNilSigner = errors.New("nil ShortID 'signer' is not valid")
|
||||
errNilTo = errors.New("nil ShortID 'to' is not valid")
|
||||
)
|
||||
|
||||
// Service defines the API calls that can be made to the platform chain
|
||||
|
@ -76,7 +79,7 @@ type GetSubnetsResponse struct {
|
|||
func (service *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, response *GetSubnetsResponse) error {
|
||||
subnets, err := service.vm.getSubnets(service.vm.DB) // all subnets
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting subnets from database: %v", err)
|
||||
return fmt.Errorf("error getting subnets from database: %w", err)
|
||||
}
|
||||
|
||||
getAll := len(args.IDs) == 0
|
||||
|
@ -278,7 +281,7 @@ type GetAccountReply struct {
|
|||
func (service *Service) GetAccount(_ *http.Request, args *GetAccountArgs, reply *GetAccountReply) error {
|
||||
account, err := service.vm.getAccount(service.vm.DB, args.Address)
|
||||
if err != nil && err != database.ErrNotFound {
|
||||
return errGetAccount
|
||||
return fmt.Errorf("couldn't get account: %w", err)
|
||||
} else if err == database.ErrNotFound {
|
||||
account = newAccount(args.Address, 0, 0)
|
||||
}
|
||||
|
@ -308,7 +311,7 @@ func (service *Service) ListAccounts(_ *http.Request, args *ListAccountsArgs, re
|
|||
// db holds the user's info that pertains to the Platform Chain
|
||||
userDB, err := service.vm.Ctx.Keystore.GetDatabase(args.Username, args.Password)
|
||||
if err != nil {
|
||||
return errGetUser
|
||||
return fmt.Errorf("couldn't get user: %w", err)
|
||||
}
|
||||
|
||||
// The user
|
||||
|
@ -319,14 +322,14 @@ func (service *Service) ListAccounts(_ *http.Request, args *ListAccountsArgs, re
|
|||
// IDs of accounts controlled by this user
|
||||
accountIDs, err := user.getAccountIDs()
|
||||
if err != nil {
|
||||
return errGetAccounts
|
||||
return fmt.Errorf("couldn't get accounts held by user: %w", err)
|
||||
}
|
||||
|
||||
reply.Accounts = []APIAccount{}
|
||||
for _, accountID := range accountIDs {
|
||||
account, err := service.vm.getAccount(service.vm.DB, accountID) // Get account whose ID is [accountID]
|
||||
if err != nil && err != database.ErrNotFound {
|
||||
service.vm.Ctx.Log.Error("couldn't get account from database: %v", err)
|
||||
service.vm.Ctx.Log.Error("couldn't get account from database: %w", err)
|
||||
continue
|
||||
} else if err == database.ErrNotFound {
|
||||
account = newAccount(accountID, 0, 0)
|
||||
|
@ -370,7 +373,7 @@ func (service *Service) CreateAccount(_ *http.Request, args *CreateAccountArgs,
|
|||
// userDB holds the user's info that pertains to the Platform Chain
|
||||
userDB, err := service.vm.Ctx.Keystore.GetDatabase(args.Username, args.Password)
|
||||
if err != nil {
|
||||
return errGetUser
|
||||
return fmt.Errorf("couldn't get user: %w", err)
|
||||
}
|
||||
|
||||
// The user creating a new account
|
||||
|
@ -428,7 +431,7 @@ type CreateTxResponse struct {
|
|||
type AddDefaultSubnetValidatorArgs struct {
|
||||
APIDefaultSubnetValidator
|
||||
|
||||
// Next unused nonce of the account the staked $AVA and tx fee are paid from
|
||||
// Next nonce of the sender
|
||||
PayerNonce json.Uint64 `json:"payerNonce"`
|
||||
}
|
||||
|
||||
|
@ -437,8 +440,13 @@ type AddDefaultSubnetValidatorArgs struct {
|
|||
func (service *Service) AddDefaultSubnetValidator(_ *http.Request, args *AddDefaultSubnetValidatorArgs, reply *CreateTxResponse) error {
|
||||
service.vm.Ctx.Log.Debug("AddDefaultSubnetValidator called")
|
||||
|
||||
if args.ID.IsZero() { // If ID unspecified, use this node's ID as validator ID
|
||||
switch {
|
||||
case args.ID.IsZero(): // If ID unspecified, use this node's ID as validator ID
|
||||
args.ID = service.vm.Ctx.NodeID
|
||||
case args.PayerNonce == 0:
|
||||
return fmt.Errorf("sender's next nonce not specified")
|
||||
case int64(args.StartTime) < time.Now().Unix():
|
||||
return fmt.Errorf("start time must be in the future")
|
||||
}
|
||||
|
||||
// Create the transaction
|
||||
|
@ -482,8 +490,13 @@ type AddDefaultSubnetDelegatorArgs struct {
|
|||
func (service *Service) AddDefaultSubnetDelegator(_ *http.Request, args *AddDefaultSubnetDelegatorArgs, reply *CreateTxResponse) error {
|
||||
service.vm.Ctx.Log.Debug("AddDefaultSubnetDelegator called")
|
||||
|
||||
if args.ID.IsZero() { // If ID unspecified, use this node's ID as validator ID
|
||||
switch {
|
||||
case args.ID.IsZero(): // If ID unspecified, use this node's ID as validator ID
|
||||
args.ID = service.vm.Ctx.NodeID
|
||||
case args.PayerNonce == 0:
|
||||
return fmt.Errorf("sender's next unused nonce not specified")
|
||||
case int64(args.StartTime) < time.Now().Unix():
|
||||
return fmt.Errorf("start time must be in the future")
|
||||
}
|
||||
|
||||
// Create the transaction
|
||||
|
@ -571,6 +584,11 @@ type CreateSubnetArgs struct {
|
|||
func (service *Service) CreateSubnet(_ *http.Request, args *CreateSubnetArgs, response *CreateTxResponse) error {
|
||||
service.vm.Ctx.Log.Debug("platform.createSubnet called")
|
||||
|
||||
switch {
|
||||
case args.PayerNonce == 0:
|
||||
return fmt.Errorf("sender's next nonce not specified")
|
||||
}
|
||||
|
||||
// Create the transaction
|
||||
tx := CreateSubnetTx{
|
||||
UnsignedCreateSubnetTx: UnsignedCreateSubnetTx{
|
||||
|
@ -612,6 +630,13 @@ type ExportAVAArgs struct {
|
|||
func (service *Service) ExportAVA(_ *http.Request, args *ExportAVAArgs, response *CreateTxResponse) error {
|
||||
service.vm.Ctx.Log.Debug("platform.ExportAVA called")
|
||||
|
||||
switch {
|
||||
case args.PayerNonce == 0:
|
||||
return fmt.Errorf("sender's next nonce not specified")
|
||||
case uint64(args.Amount) == 0:
|
||||
return fmt.Errorf("amount must be >0")
|
||||
}
|
||||
|
||||
// Create the transaction
|
||||
tx := ExportTx{UnsignedExportTx: UnsignedExportTx{
|
||||
NetworkID: service.vm.Ctx.NetworkID,
|
||||
|
@ -667,6 +692,10 @@ type SignResponse struct {
|
|||
func (service *Service) Sign(_ *http.Request, args *SignArgs, reply *SignResponse) error {
|
||||
service.vm.Ctx.Log.Debug("sign called")
|
||||
|
||||
if args.Signer.IsZero() {
|
||||
return errNilSigner
|
||||
}
|
||||
|
||||
// Get the key of the Signer
|
||||
db, err := service.vm.Ctx.Keystore.GetDatabase(args.Username, args.Password)
|
||||
if err != nil {
|
||||
|
@ -719,7 +748,7 @@ func (service *Service) signAddDefaultSubnetValidatorTx(tx *addDefaultSubnetVali
|
|||
unsignedIntf := interface{}(&tx.UnsignedAddDefaultSubnetValidatorTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
|
@ -742,7 +771,7 @@ func (service *Service) signAddDefaultSubnetDelegatorTx(tx *addDefaultSubnetDele
|
|||
unsignedIntf := interface{}(&tx.UnsignedAddDefaultSubnetDelegatorTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
|
@ -765,7 +794,7 @@ func (service *Service) signCreateSubnetTx(tx *CreateSubnetTx, key *crypto.Priva
|
|||
unsignedIntf := interface{}(&tx.UnsignedCreateSubnetTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
|
@ -788,7 +817,7 @@ func (service *Service) signExportTx(tx *ExportTx, key *crypto.PrivateKeySECP256
|
|||
unsignedIntf := interface{}(&tx.UnsignedExportTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
|
@ -816,7 +845,7 @@ func (service *Service) signAddNonDefaultSubnetValidatorTx(tx *addNonDefaultSubn
|
|||
unsignedIntf := interface{}(&tx.UnsignedAddNonDefaultSubnetValidatorTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
if err != nil {
|
||||
|
@ -829,7 +858,7 @@ func (service *Service) signAddNonDefaultSubnetValidatorTx(tx *addNonDefaultSubn
|
|||
// Get information about the subnet
|
||||
subnet, err := service.vm.getSubnet(service.vm.DB, tx.SubnetID())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("problem getting subnet information: %v", err)
|
||||
return nil, fmt.Errorf("problem getting subnet information: %w", err)
|
||||
}
|
||||
|
||||
// Find the location at which [key] should put its signature.
|
||||
|
@ -861,7 +890,7 @@ type ImportAVAArgs struct {
|
|||
// ID of the account that will receive the imported funds, and pay the transaction fee
|
||||
To ids.ShortID `json:"to"`
|
||||
|
||||
// Next unused nonce of the account
|
||||
// Next nonce of the sender
|
||||
PayerNonce json.Uint64 `json:"payerNonce"`
|
||||
|
||||
// User that controls the account
|
||||
|
@ -875,10 +904,17 @@ type ImportAVAArgs struct {
|
|||
func (service *Service) ImportAVA(_ *http.Request, args *ImportAVAArgs, response *SignResponse) error {
|
||||
service.vm.Ctx.Log.Debug("platform.ImportAVA called")
|
||||
|
||||
switch {
|
||||
case args.To.IsZero():
|
||||
return errNilTo
|
||||
case args.PayerNonce == 0:
|
||||
return fmt.Errorf("sender's next nonce not specified")
|
||||
}
|
||||
|
||||
// Get the key of the Signer
|
||||
db, err := service.vm.Ctx.Keystore.GetDatabase(args.Username, args.Password)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get data for user '%s'. Does user exist?", args.Username)
|
||||
return fmt.Errorf("couldn't get user: %w", err)
|
||||
}
|
||||
user := user{db: db}
|
||||
|
||||
|
@ -991,7 +1027,7 @@ func (service *Service) signCreateChainTx(tx *CreateChainTx, key *crypto.Private
|
|||
unsignedIntf := interface{}(&tx.UnsignedCreateChainTx)
|
||||
unsignedTxBytes, err := Codec.Marshal(&unsignedIntf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %v", err)
|
||||
return nil, fmt.Errorf("error serializing unsigned tx: %w", err)
|
||||
}
|
||||
sig, err := key.Sign(unsignedTxBytes)
|
||||
if err != nil {
|
||||
|
@ -1004,7 +1040,7 @@ func (service *Service) signCreateChainTx(tx *CreateChainTx, key *crypto.Private
|
|||
// Get information about the subnet
|
||||
subnet, err := service.vm.getSubnet(service.vm.DB, tx.SubnetID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("problem getting subnet information: %v", err)
|
||||
return nil, fmt.Errorf("problem getting subnet information: %w", err)
|
||||
}
|
||||
|
||||
// Find the location at which [key] should put its signature.
|
||||
|
@ -1099,7 +1135,7 @@ type CreateBlockchainArgs struct {
|
|||
// Human-readable name for the new blockchain, not necessarily unique
|
||||
Name string `json:"name"`
|
||||
|
||||
// Next unused nonce of the account paying the transaction fee
|
||||
// Next nonce of the sender
|
||||
PayerNonce json.Uint64 `json:"payerNonce"`
|
||||
|
||||
// Genesis state of the blockchain being created
|
||||
|
@ -1111,6 +1147,15 @@ type CreateBlockchainArgs struct {
|
|||
func (service *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs, response *CreateTxResponse) error {
|
||||
service.vm.Ctx.Log.Debug("createBlockchain called")
|
||||
|
||||
switch {
|
||||
case args.PayerNonce == 0:
|
||||
return errors.New("sender's next nonce not specified")
|
||||
case args.VMID == "":
|
||||
return errors.New("VM not specified")
|
||||
case args.SubnetID.Equals(ids.Empty):
|
||||
return errors.New("subnet not specified")
|
||||
}
|
||||
|
||||
vmID, err := service.vm.chainManager.LookupVM(args.VMID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("no VM with ID '%s' found", args.VMID)
|
||||
|
@ -1156,7 +1201,7 @@ func (service *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchain
|
|||
|
||||
txBytes, err := Codec.Marshal(genericTx{Tx: &tx})
|
||||
if err != nil {
|
||||
service.vm.Ctx.Log.Error("problem marshaling createChainTx: %v", err)
|
||||
service.vm.Ctx.Log.Error("problem marshaling createChainTx: %w", err)
|
||||
return errCreatingTransaction
|
||||
}
|
||||
|
||||
|
@ -1180,6 +1225,11 @@ type GetBlockchainStatusReply struct {
|
|||
func (service *Service) GetBlockchainStatus(_ *http.Request, args *GetBlockchainStatusArgs, reply *GetBlockchainStatusReply) error {
|
||||
service.vm.Ctx.Log.Debug("getBlockchainStatus called")
|
||||
|
||||
switch {
|
||||
case args.BlockchainID == "":
|
||||
return errors.New("'blockchainID' not given")
|
||||
}
|
||||
|
||||
_, err := service.vm.chainManager.Lookup(args.BlockchainID)
|
||||
if err == nil {
|
||||
reply.Status = Validating
|
||||
|
@ -1255,6 +1305,11 @@ type ValidatedByResponse struct {
|
|||
func (service *Service) ValidatedBy(_ *http.Request, args *ValidatedByArgs, response *ValidatedByResponse) error {
|
||||
service.vm.Ctx.Log.Debug("validatedBy called")
|
||||
|
||||
switch {
|
||||
case args.BlockchainID.Equals(ids.Empty):
|
||||
return errors.New("'blockchainID' not specified")
|
||||
}
|
||||
|
||||
chain, err := service.vm.getChain(service.vm.DB, args.BlockchainID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1277,6 +1332,11 @@ type ValidatesResponse struct {
|
|||
func (service *Service) Validates(_ *http.Request, args *ValidatesArgs, response *ValidatesResponse) error {
|
||||
service.vm.Ctx.Log.Debug("validates called")
|
||||
|
||||
switch {
|
||||
case args.SubnetID.Equals(ids.Empty):
|
||||
return errors.New("'subnetID' not specified")
|
||||
}
|
||||
|
||||
// Verify that the Subnet exists
|
||||
if _, err := service.vm.getSubnet(service.vm.DB, args.SubnetID); err != nil {
|
||||
return err
|
||||
|
@ -1322,7 +1382,7 @@ func (service *Service) GetBlockchains(_ *http.Request, args *struct{}, response
|
|||
|
||||
chains, err := service.vm.getChains(service.vm.DB)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't retrieve blockchains: %v", err)
|
||||
return fmt.Errorf("couldn't retrieve blockchains: %w", err)
|
||||
}
|
||||
|
||||
for _, chain := range chains {
|
||||
|
|
|
@ -405,7 +405,12 @@ func (vm *VM) Shutdown() {
|
|||
return
|
||||
}
|
||||
|
||||
// There is a potential deadlock if the timer is about to execute a timeout.
|
||||
// So, the lock must be released before stopping the timer.
|
||||
vm.Ctx.Lock.Unlock()
|
||||
vm.timer.Stop()
|
||||
vm.Ctx.Lock.Lock()
|
||||
|
||||
if err := vm.DB.Close(); err != nil {
|
||||
vm.Ctx.Log.Error("Closing the database failed with %s", err)
|
||||
}
|
||||
|
|
|
@ -142,6 +142,8 @@ func defaultVM() *VM {
|
|||
db := memdb.New()
|
||||
msgChan := make(chan common.Message, 1)
|
||||
ctx := defaultContext()
|
||||
ctx.Lock.Lock()
|
||||
defer ctx.Lock.Unlock()
|
||||
if err := vm.Initialize(ctx, db, genesisBytes, msgChan, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -233,6 +235,11 @@ func GenesisCurrentValidators() *EventHeap {
|
|||
// Ensure genesis state is parsed from bytes and stored correctly
|
||||
func TestGenesis(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Ensure the genesis block has been accepted and stored
|
||||
genesisBlockID := vm.LastAccepted() // lastAccepted should be ID of genesis block
|
||||
|
@ -302,6 +309,12 @@ func TestGenesis(t *testing.T) {
|
|||
// accept proposal to add validator to default subnet
|
||||
func TestAddDefaultSubnetValidatorCommit(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
startTime := defaultGenesisTime.Add(Delta).Add(1 * time.Second)
|
||||
endTime := startTime.Add(MinimumStakingDuration)
|
||||
key, _ := vm.factory.NewPrivateKey()
|
||||
|
@ -325,12 +338,10 @@ func TestAddDefaultSubnetValidatorCommit(t *testing.T) {
|
|||
|
||||
// trigger block creation
|
||||
vm.unissuedEvents.Add(tx)
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -369,6 +380,12 @@ func TestAddDefaultSubnetValidatorCommit(t *testing.T) {
|
|||
// Reject proposal to add validator to default subnet
|
||||
func TestAddDefaultSubnetValidatorReject(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
startTime := defaultGenesisTime.Add(Delta).Add(1 * time.Second)
|
||||
endTime := startTime.Add(MinimumStakingDuration)
|
||||
key, _ := vm.factory.NewPrivateKey()
|
||||
|
@ -392,12 +409,10 @@ func TestAddDefaultSubnetValidatorReject(t *testing.T) {
|
|||
|
||||
// trigger block creation
|
||||
vm.unissuedEvents.Add(tx)
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -440,6 +455,12 @@ func TestAddDefaultSubnetValidatorReject(t *testing.T) {
|
|||
// Accept proposal to add validator to non-default subnet
|
||||
func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
startTime := defaultValidateStartTime.Add(Delta).Add(1 * time.Second)
|
||||
endTime := startTime.Add(MinimumStakingDuration)
|
||||
|
||||
|
@ -463,12 +484,10 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
|
|||
|
||||
// trigger block creation
|
||||
vm.unissuedEvents.Add(tx)
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -511,6 +530,12 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
|
|||
// Reject proposal to add validator to non-default subnet
|
||||
func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
startTime := defaultValidateStartTime.Add(Delta).Add(1 * time.Second)
|
||||
endTime := startTime.Add(MinimumStakingDuration)
|
||||
key, _ := vm.factory.NewPrivateKey()
|
||||
|
@ -536,12 +561,10 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
|
|||
|
||||
// trigger block creation
|
||||
vm.unissuedEvents.Add(tx)
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -584,16 +607,19 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
|
|||
// Test case where default subnet validator rewarded
|
||||
func TestRewardValidatorAccept(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Fast forward clock to time for genesis validators to leave
|
||||
vm.clock.Set(defaultValidateEndTime)
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock() // should contain proposal to advance time
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -630,12 +656,10 @@ func TestRewardValidatorAccept(t *testing.T) {
|
|||
t.Fatal("expected timestamp to have advanced")
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err = vm.BuildBlock() // should contain proposal to reward genesis validator
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block = blk.(*ProposalBlock)
|
||||
|
@ -676,16 +700,19 @@ func TestRewardValidatorAccept(t *testing.T) {
|
|||
// Test case where default subnet validator not rewarded
|
||||
func TestRewardValidatorReject(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
// Fast forward clock to time for genesis validators to leave
|
||||
vm.clock.Set(defaultValidateEndTime)
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err := vm.BuildBlock() // should contain proposal to advance time
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block := blk.(*ProposalBlock)
|
||||
|
@ -722,12 +749,10 @@ func TestRewardValidatorReject(t *testing.T) {
|
|||
t.Fatal("expected timestamp to have advanced")
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err = vm.BuildBlock() // should contain proposal to reward genesis validator
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
block = blk.(*ProposalBlock)
|
||||
|
@ -768,6 +793,11 @@ func TestRewardValidatorReject(t *testing.T) {
|
|||
// Ensure BuildBlock errors when there is no block to build
|
||||
func TestUnneededBuildBlock(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
if _, err := vm.BuildBlock(); err == nil {
|
||||
t.Fatalf("Should have errored on BuildBlock")
|
||||
|
@ -777,6 +807,11 @@ func TestUnneededBuildBlock(t *testing.T) {
|
|||
// test acceptance of proposal to create a new chain
|
||||
func TestCreateChain(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
|
@ -793,13 +828,11 @@ func TestCreateChain(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
vm.unissuedDecisionTxs = append(vm.unissuedDecisionTxs, tx)
|
||||
blk, err := vm.BuildBlock() // should contain proposal to create chain
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
if err := blk.Verify(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -839,6 +872,11 @@ func TestCreateChain(t *testing.T) {
|
|||
// 4) Advance timestamp to validator's end time (removing validator from current)
|
||||
func TestCreateSubnet(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
createSubnetTx, err := vm.newCreateSubnetTx(
|
||||
testNetworkID,
|
||||
|
@ -854,13 +892,11 @@ func TestCreateSubnet(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
vm.unissuedDecisionTxs = append(vm.unissuedDecisionTxs, createSubnetTx)
|
||||
blk, err := vm.BuildBlock() // should contain proposal to create subnet
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
if err := blk.Verify(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -917,13 +953,11 @@ func TestCreateSubnet(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
vm.unissuedEvents.Push(addValidatorTx)
|
||||
blk, err = vm.BuildBlock() // should add validator to the new subnet
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
// and accept the proposal/commit
|
||||
|
@ -971,12 +1005,10 @@ func TestCreateSubnet(t *testing.T) {
|
|||
// from pending to current validator set
|
||||
vm.clock.Set(startTime)
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err = vm.BuildBlock() // should be advance time tx
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
// and accept the proposal/commit
|
||||
|
@ -1031,12 +1063,10 @@ func TestCreateSubnet(t *testing.T) {
|
|||
|
||||
// fast forward clock to time validator should stop validating
|
||||
vm.clock.Set(endTime)
|
||||
vm.Ctx.Lock.Lock()
|
||||
blk, err = vm.BuildBlock() // should be advance time tx
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vm.Ctx.Lock.Unlock()
|
||||
|
||||
// Assert preferences are correct
|
||||
// and accept the proposal/commit
|
||||
|
@ -1084,6 +1114,11 @@ func TestCreateSubnet(t *testing.T) {
|
|||
// test asset import
|
||||
func TestAtomicImport(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
avmID := ids.Empty.Prefix(0)
|
||||
utxoID := ava.UTXOID{
|
||||
|
@ -1117,9 +1152,6 @@ func TestAtomicImport(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer vm.Ctx.Lock.Unlock()
|
||||
|
||||
vm.ava = assetID
|
||||
vm.avm = avmID
|
||||
|
||||
|
@ -1175,6 +1207,11 @@ func TestAtomicImport(t *testing.T) {
|
|||
// test optimistic asset import
|
||||
func TestOptimisticAtomicImport(t *testing.T) {
|
||||
vm := defaultVM()
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
vm.Ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
avmID := ids.Empty.Prefix(0)
|
||||
utxoID := ava.UTXOID{
|
||||
|
@ -1208,9 +1245,6 @@ func TestOptimisticAtomicImport(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm.Ctx.Lock.Lock()
|
||||
defer vm.Ctx.Lock.Unlock()
|
||||
|
||||
vm.ava = assetID
|
||||
vm.avm = avmID
|
||||
|
||||
|
@ -1271,6 +1305,8 @@ func TestRestartPartiallyAccepted(t *testing.T) {
|
|||
|
||||
firstVM.clock.Set(defaultGenesisTime)
|
||||
firstCtx := defaultContext()
|
||||
firstCtx.Lock.Lock()
|
||||
|
||||
firstMsgChan := make(chan common.Message, 1)
|
||||
if err := firstVM.Initialize(firstCtx, db, genesisBytes, firstMsgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1318,6 +1354,7 @@ func TestRestartPartiallyAccepted(t *testing.T) {
|
|||
}
|
||||
|
||||
firstVM.Shutdown()
|
||||
firstCtx.Lock.Unlock()
|
||||
|
||||
secondVM := &VM{
|
||||
SnowmanVM: &core.SnowmanVM{},
|
||||
|
@ -1330,6 +1367,12 @@ func TestRestartPartiallyAccepted(t *testing.T) {
|
|||
|
||||
secondVM.clock.Set(defaultGenesisTime)
|
||||
secondCtx := defaultContext()
|
||||
secondCtx.Lock.Lock()
|
||||
defer func() {
|
||||
secondVM.Shutdown()
|
||||
secondCtx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
secondMsgChan := make(chan common.Message, 1)
|
||||
if err := secondVM.Initialize(secondCtx, db, genesisBytes, secondMsgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1371,6 +1414,8 @@ func TestRestartFullyAccepted(t *testing.T) {
|
|||
|
||||
firstVM.clock.Set(defaultGenesisTime)
|
||||
firstCtx := defaultContext()
|
||||
firstCtx.Lock.Lock()
|
||||
|
||||
firstMsgChan := make(chan common.Message, 1)
|
||||
if err := firstVM.Initialize(firstCtx, db, genesisBytes, firstMsgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1418,6 +1463,7 @@ func TestRestartFullyAccepted(t *testing.T) {
|
|||
}
|
||||
|
||||
firstVM.Shutdown()
|
||||
firstCtx.Lock.Unlock()
|
||||
|
||||
secondVM := &VM{
|
||||
SnowmanVM: &core.SnowmanVM{},
|
||||
|
@ -1430,6 +1476,12 @@ func TestRestartFullyAccepted(t *testing.T) {
|
|||
|
||||
secondVM.clock.Set(defaultGenesisTime)
|
||||
secondCtx := defaultContext()
|
||||
secondCtx.Lock.Lock()
|
||||
defer func() {
|
||||
secondVM.Shutdown()
|
||||
secondCtx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
secondMsgChan := make(chan common.Message, 1)
|
||||
if err := secondVM.Initialize(secondCtx, db, genesisBytes, secondMsgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1471,7 +1523,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) {
|
|||
SnowmanVM: &core.SnowmanVM{},
|
||||
chainManager: chains.MockManager{},
|
||||
}
|
||||
defer vm.Shutdown()
|
||||
|
||||
defaultSubnet := validators.NewSet()
|
||||
vm.validators = validators.NewManager()
|
||||
|
@ -1479,9 +1530,9 @@ func TestBootstrapPartiallyAccepted(t *testing.T) {
|
|||
|
||||
vm.clock.Set(defaultGenesisTime)
|
||||
ctx := defaultContext()
|
||||
msgChan := make(chan common.Message, 1)
|
||||
|
||||
ctx.Lock.Lock()
|
||||
|
||||
msgChan := make(chan common.Message, 1)
|
||||
if err := vm.Initialize(ctx, vmDB, genesisBytes, msgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1581,6 +1632,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) {
|
|||
|
||||
externalSender.GetF = nil
|
||||
externalSender.CantPushQuery = false
|
||||
externalSender.CantPullQuery = false
|
||||
|
||||
engine.Put(ctx.NodeID, *reqID, advanceTimeBlkID, advanceTimeBlkBytes)
|
||||
|
||||
|
@ -1627,6 +1679,12 @@ func TestUnverifiedParent(t *testing.T) {
|
|||
|
||||
vm.clock.Set(defaultGenesisTime)
|
||||
ctx := defaultContext()
|
||||
ctx.Lock.Lock()
|
||||
defer func() {
|
||||
vm.Shutdown()
|
||||
ctx.Lock.Unlock()
|
||||
}()
|
||||
|
||||
msgChan := make(chan common.Message, 1)
|
||||
if err := vm.Initialize(ctx, db, genesisBytes, msgChan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -66,6 +66,7 @@ func ConsensusLeader(numBlocks, numTxsPerBlock int, b *testing.B) {
|
|||
|
||||
// Initialize the VM
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
ctx.Lock.Lock()
|
||||
if err := vm.Initialize(ctx, vmDB, genesisData, msgChan, nil); err != nil {
|
||||
b.Fatal(err)
|
||||
|
@ -198,6 +199,7 @@ func ConsensusFollower(numBlocks, numTxsPerBlock int, b *testing.B) {
|
|||
vm := &VM{
|
||||
onAccept: func(ids.ID) { wg.Done() },
|
||||
}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
ctx.Lock.Lock()
|
||||
if err := vm.Initialize(ctx, vmDB, genesisData, msgChan, nil); err != nil {
|
||||
b.Fatal(err)
|
||||
|
|
|
@ -122,7 +122,11 @@ func (vm *VM) Shutdown() {
|
|||
return
|
||||
}
|
||||
|
||||
// There is a potential deadlock if the timer is about to execute a timeout.
|
||||
// So, the lock must be released before stopping the timer.
|
||||
vm.ctx.Lock.Unlock()
|
||||
vm.timer.Stop()
|
||||
vm.ctx.Lock.Lock()
|
||||
if err := vm.baseDB.Close(); err != nil {
|
||||
vm.ctx.Log.Error("Closing the database failed with %s", err)
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ func BenchmarkParseBlock(b *testing.B) {
|
|||
/*testing=*/ b,
|
||||
)
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(
|
||||
/*ctx=*/ ctx,
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -106,6 +107,7 @@ func BenchmarkParseAndVerify(b *testing.B) {
|
|||
|
||||
for n := 0; n < b.N; n++ {
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(
|
||||
/*ctx=*/ snow.DefaultContextTest(),
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -141,6 +143,8 @@ func BenchmarkAccept(b *testing.B) {
|
|||
|
||||
for n := 0; n < b.N; n++ {
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
|
||||
vm.Initialize(
|
||||
/*ctx=*/ snow.DefaultContextTest(),
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -178,6 +182,7 @@ func ParseAndVerifyAndAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
|
|||
|
||||
for n := 0; n < b.N; n++ {
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(
|
||||
/*ctx=*/ snow.DefaultContextTest(),
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -232,6 +237,7 @@ func ParseThenVerifyThenAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
|
|||
|
||||
for n := 0; n < b.N; n++ {
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(
|
||||
/*ctx=*/ snow.DefaultContextTest(),
|
||||
/*db=*/ memdb.New(),
|
||||
|
@ -292,6 +298,7 @@ func IssueAndVerifyAndAccept(numBlocks, numTxsPerBlock int, b *testing.B) {
|
|||
|
||||
for n := 0; n < b.N; n++ {
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(
|
||||
/*ctx=*/ snow.DefaultContextTest(),
|
||||
/*db=*/ memdb.New(),
|
||||
|
|
|
@ -67,6 +67,7 @@ func TestPayments(t *testing.T) {
|
|||
blocker, _ := queue.New(bootstrappingDB)
|
||||
|
||||
vm := &VM{}
|
||||
defer func() { ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(ctx, db, genesisData, msgChan, nil)
|
||||
|
||||
sender := &common.SenderTest{}
|
||||
|
|
|
@ -134,7 +134,11 @@ func (vm *VM) Shutdown() {
|
|||
return
|
||||
}
|
||||
|
||||
// There is a potential deadlock if the timer is about to execute a timeout.
|
||||
// So, the lock must be released before stopping the timer.
|
||||
vm.ctx.Lock.Unlock()
|
||||
vm.timer.Stop()
|
||||
vm.ctx.Lock.Lock()
|
||||
if err := vm.baseDB.Close(); err != nil {
|
||||
vm.ctx.Log.Error("Closing the database failed with %s", err)
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ func TestAva(t *testing.T) {
|
|||
msgChan := make(chan common.Message, 1)
|
||||
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
vm.batchTimeout = 0
|
||||
|
||||
|
@ -172,6 +173,7 @@ func TestInvalidSpentTx(t *testing.T) {
|
|||
msgChan := make(chan common.Message, 1)
|
||||
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
|
||||
ctx.Lock.Lock()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
|
@ -258,6 +260,7 @@ func TestInvalidTxVerification(t *testing.T) {
|
|||
msgChan := make(chan common.Message, 1)
|
||||
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
|
||||
ctx.Lock.Lock()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
|
@ -319,6 +322,7 @@ func TestRPCAPI(t *testing.T) {
|
|||
vmDB := memdb.New()
|
||||
msgChan := make(chan common.Message, 1)
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
vm.batchTimeout = 0
|
||||
|
||||
|
@ -526,6 +530,7 @@ func TestMultipleSend(t *testing.T) {
|
|||
vmDB := memdb.New()
|
||||
msgChan := make(chan common.Message, 1)
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
|
||||
// Initialize these data structures
|
||||
|
@ -635,6 +640,7 @@ func TestIssuePendingDependency(t *testing.T) {
|
|||
|
||||
ctx.Lock.Lock()
|
||||
vm := &VM{}
|
||||
defer func() { vm.ctx.Lock.Lock(); vm.Shutdown(); vm.ctx.Lock.Unlock() }()
|
||||
vm.Initialize(ctx, vmDB, genesisTx.Bytes(), msgChan, nil)
|
||||
vm.batchTimeout = 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue