From c6fcd057903dc5ccc785b3a34fef534a4cb39d0a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Sun, 1 Nov 2020 18:24:33 -0500 Subject: remove id.Bytes() and ids.NewID --- plugin/evm/import_tx_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'plugin/evm/import_tx_test.go') diff --git a/plugin/evm/import_tx_test.go b/plugin/evm/import_tx_test.go index fcd18ac..52a8fa7 100644 --- a/plugin/evm/import_tx_test.go +++ b/plugin/evm/import_tx_test.go @@ -22,7 +22,7 @@ func TestImportTxVerifyNil(t *testing.T) { func TestImportTxVerify(t *testing.T) { var importAmount uint64 = 10000000 - txID := ids.NewID([32]byte{0xff}) + txID := [32]byte{0xff} importTx := &UnsignedImportTx{ NetworkID: testNetworkID, BlockchainID: testCChainID, @@ -134,12 +134,12 @@ func TestImportTxSemanticVerify(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: ids.NewID([32]byte{ + TxID: [32]byte{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, 0x09, 0x29, 0x49, 0x69, 0x88, 0xa8, 0xc8, 0xe8, - }), + }, } utxo := &avax.UTXO{ @@ -203,9 +203,9 @@ func TestImportTxSemanticVerify(t *testing.T) { if err := unsignedImportTx.SemanticVerify(vm, tx); err != nil { t.Fatal("Should have failed to import non-existent UTXO") } - + inputID := utxo.InputID() if err := xChainSharedMemory.Put(vm.ctx.ChainID, []*atomic.Element{{ - Key: utxo.InputID().Bytes(), + Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ testKeys[0].PublicKey().Address().Bytes(), @@ -293,12 +293,12 @@ func TestNewImportTx(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: ids.NewID([32]byte{ + TxID: [32]byte{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, 0x09, 0x29, 0x49, 0x69, 0x88, 0xa8, 0xc8, 0xe8, - }), + }, } utxo := &avax.UTXO{ @@ -318,9 +318,9 @@ func TestNewImportTx(t *testing.T) { } xChainSharedMemory := sharedMemory.NewSharedMemory(vm.ctx.XChainID) - + inputID := utxo.InputID() if err := xChainSharedMemory.Put(vm.ctx.ChainID, []*atomic.Element{{ - Key: utxo.InputID().Bytes(), + Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ testKeys[0].PublicKey().Address().Bytes(), -- cgit v1.2.3-70-g09d2 From 52de74ce47a2614af3b3a32b21aa5309d4b00d78 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Sun, 1 Nov 2020 18:32:22 -0500 Subject: lint --- plugin/evm/export_tx_test.go | 2 +- plugin/evm/import_tx_test.go | 4 ++-- plugin/evm/tx.go | 4 ---- plugin/evm/user.go | 5 ++--- plugin/evm/vm.go | 29 ++--------------------------- plugin/evm/vm_test.go | 18 ++++++++---------- 6 files changed, 15 insertions(+), 47 deletions(-) (limited to 'plugin/evm/import_tx_test.go') diff --git a/plugin/evm/export_tx_test.go b/plugin/evm/export_tx_test.go index 319c6dd..6fdf3a2 100644 --- a/plugin/evm/export_tx_test.go +++ b/plugin/evm/export_tx_test.go @@ -76,7 +76,7 @@ func TestExportTxVerify(t *testing.T) { // Test Valid Export Tx if err := exportTx.Verify(testXChainID, ctx, testTxFee, testAvaxAssetID); err != nil { - t.Fatalf("Failed to verify valid ExportTx: %w", err) + t.Fatalf("Failed to verify valid ExportTx: %s", err) } exportTx.syntacticallyVerified = false diff --git a/plugin/evm/import_tx_test.go b/plugin/evm/import_tx_test.go index 52a8fa7..b0f2875 100644 --- a/plugin/evm/import_tx_test.go +++ b/plugin/evm/import_tx_test.go @@ -77,7 +77,7 @@ func TestImportTxVerify(t *testing.T) { // Test Valid ImportTx if err := importTx.Verify(testXChainID, ctx, testTxFee, testAvaxAssetID); err != nil { - t.Fatalf("Failed to verify ImportTx: %w", err) + t.Fatalf("Failed to verify ImportTx: %s", err) } importTx.syntacticallyVerified = false @@ -268,7 +268,7 @@ func TestImportTxSemanticVerify(t *testing.T) { } if err := unsignedImportTx.Accept(vm.ctx, nil); err != nil { - t.Fatalf("Accept failed due to: %w", err) + t.Fatalf("Accept failed due to: %s", err) } if err := unsignedImportTx.EVMStateTransfer(vm, state); err != nil { diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go index 3a2f820..e44eefe 100644 --- a/plugin/evm/tx.go +++ b/plugin/evm/tx.go @@ -23,10 +23,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// Max size of memo field -// Don't change without also changing avm.maxMemoSize -const maxMemoSize = 256 - var ( errWrongBlockchainID = errors.New("wrong blockchain ID provided") errWrongNetworkID = errors.New("tx was issued with a different network ID") diff --git a/plugin/evm/user.go b/plugin/evm/user.go index 152156d..0ab1863 100644 --- a/plugin/evm/user.go +++ b/plugin/evm/user.go @@ -18,9 +18,8 @@ import ( var addressesKey = ids.Empty[:] var ( - errDBNil = errors.New("db uninitialized") - errKeyNil = errors.New("key uninitialized") - errEmptyAddress = errors.New("address is empty") + errDBNil = errors.New("db uninitialized") + errKeyNil = errors.New("key uninitialized") ) type user struct { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 2ab4028..c191720 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -57,10 +57,6 @@ import ( ) var ( - zeroAddr = common.Address{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - } x2cRate = big.NewInt(1000000000) ) @@ -83,10 +79,6 @@ const ( bdTimerStateLong ) -const ( - addressSep = "-" -) - var ( txFee = units.MilliAvax @@ -99,21 +91,14 @@ var ( errInvalidAddr = errors.New("invalid hex address") errTooManyAtomicTx = errors.New("too many pending atomic txs") errAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo") - errWrongNumberOfCredentials = errors.New("should have the same number of credentials as inputs") - errNoInputs = errors.New("tx has no inputs") errNoImportInputs = errors.New("tx has no imported inputs") errInputsNotSortedUnique = errors.New("inputs not sorted and unique") errPublicKeySignatureMismatch = errors.New("signature doesn't match public key") errSignatureInputsMismatch = errors.New("number of inputs does not match number of signatures") - errUnknownAsset = errors.New("unknown asset ID") - errNoFunds = errors.New("no spendable funds were found") errWrongChainID = errors.New("tx has wrong chain ID") errInsufficientFunds = errors.New("insufficient funds") errNoExportOutputs = errors.New("tx has no export outputs") errOutputsNotSorted = errors.New("tx outputs not sorted") - errNoImportOutputs = errors.New("tx has no outputs to import") - errNoExportInputs = errors.New("tx has no inputs to export") - errInputsNotSortedAndUnique = errors.New("inputs not sorted and unique") errOverflowExport = errors.New("overflow when computing export amount + txFee") errInvalidNonce = errors.New("invalid nonce") ) @@ -457,8 +442,8 @@ func (vm *VM) ParseBlock(b []byte) (snowman.Block, error) { } blockHash := ethBlock.Hash() // Coinbase must be zero on C-Chain - if bytes.Compare(blockHash.Bytes(), vm.genesisHash.Bytes()) != 0 && - bytes.Compare(ethBlock.Coinbase().Bytes(), coreth.BlackholeAddr.Bytes()) != 0 { + if !bytes.Equal(blockHash.Bytes(), vm.genesisHash.Bytes()) && + !bytes.Equal(ethBlock.Coinbase().Bytes(), coreth.BlackholeAddr.Bytes()) { return nil, errInvalidBlock } block := &Block{ @@ -715,16 +700,6 @@ func (vm *VM) getBlock(id ids.ID) *Block { return block } -func (vm *VM) issueRemoteTxs(txs []*types.Transaction) error { - errs := vm.chain.AddRemoteTxs(txs) - for _, err := range errs { - if err != nil { - return err - } - } - return vm.tryBlockGen() -} - func (vm *VM) writeBackMetadata() { vm.metalock.Lock() defer vm.metalock.Unlock() diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 1117d0d..d58fdda 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -27,14 +27,12 @@ var ( testXChainID = ids.ID([32]byte{'t', 'e', 's', 't', 'x'}) nonExistentID = ids.ID([32]byte{'F'}) testTxFee = uint64(1000) - startBalance = uint64(50000) testKeys []*crypto.PrivateKeySECP256K1R testEthAddrs []common.Address // testEthAddrs[i] corresponds to testKeys[i] testShortIDAddrs []ids.ShortID - testAvaxAssetID = [32]byte{1, 2, 3} - username = "Johns" - password = "CjasdjhiPeirbSenfeI13" // #nosec G101 - ethChainID uint32 = 43112 + testAvaxAssetID = [32]byte{1, 2, 3} + username = "Johns" + password = "CjasdjhiPeirbSenfeI13" // #nosec G101 ) func init() { @@ -63,7 +61,7 @@ func BuildGenesisTest(t *testing.T) []byte { genesis := &core.Genesis{} if err := json.Unmarshal([]byte(genesisJSON), genesis); err != nil { - t.Fatalf("Problem unmarshaling genesis JSON: %w", err) + t.Fatalf("Problem unmarshaling genesis JSON: %s", err) } genesisReply, err := ss.BuildGenesis(nil, genesis) if err != nil { @@ -79,10 +77,10 @@ func NewContext() *snow.Context { ctx.AVAXAssetID = testAvaxAssetID ctx.XChainID = ids.Empty.Prefix(0) aliaser := ctx.BCLookup.(*ids.Aliaser) - aliaser.Alias(testCChainID, "C") - aliaser.Alias(testCChainID, testCChainID.String()) - aliaser.Alias(testXChainID, "X") - aliaser.Alias(testXChainID, testXChainID.String()) + _ = aliaser.Alias(testCChainID, "C") + _ = aliaser.Alias(testCChainID, testCChainID.String()) + _ = aliaser.Alias(testXChainID, "X") + _ = aliaser.Alias(testXChainID, testXChainID.String()) // SNLookup might be required here??? return ctx -- cgit v1.2.3-70-g09d2 From d7f430c196e0856eaaeedbfe1fcc30c1c472cd43 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Mon, 9 Nov 2020 13:46:28 -0500 Subject: Clean up usage of ids.ID --- plugin/evm/export_tx.go | 2 -- plugin/evm/factory.go | 2 +- plugin/evm/import_tx.go | 2 -- plugin/evm/import_tx_test.go | 6 +++--- plugin/evm/service.go | 2 +- plugin/evm/vm_test.go | 8 ++++---- 6 files changed, 9 insertions(+), 13 deletions(-) (limited to 'plugin/evm/import_tx_test.go') diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 0778d0a..ed069d4 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -53,8 +53,6 @@ func (tx *UnsignedExportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.DestinationChain == ids.Empty: - return errWrongChainID case tx.DestinationChain != avmID: return errWrongChainID case len(tx.ExportedOutputs) == 0: diff --git a/plugin/evm/factory.go b/plugin/evm/factory.go index b977117..daedf39 100644 --- a/plugin/evm/factory.go +++ b/plugin/evm/factory.go @@ -7,7 +7,7 @@ import "github.com/ava-labs/avalanchego/ids" // ID this VM should be referenced by var ( - ID = ids.ID([32]byte{'e', 'v', 'm'}) + ID = ids.ID{'e', 'v', 'm'} ) // Factory ... diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index 2ce8f6f..23dbc5f 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -58,8 +58,6 @@ func (tx *UnsignedImportTx) Verify( return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.SourceChain == ids.Empty: - return errWrongChainID case tx.SourceChain != avmID: return errWrongChainID case len(tx.ImportedInputs) == 0: diff --git a/plugin/evm/import_tx_test.go b/plugin/evm/import_tx_test.go index b0f2875..53b9494 100644 --- a/plugin/evm/import_tx_test.go +++ b/plugin/evm/import_tx_test.go @@ -22,7 +22,7 @@ func TestImportTxVerifyNil(t *testing.T) { func TestImportTxVerify(t *testing.T) { var importAmount uint64 = 10000000 - txID := [32]byte{0xff} + txID := ids.ID{0xff} importTx := &UnsignedImportTx{ NetworkID: testNetworkID, BlockchainID: testCChainID, @@ -134,7 +134,7 @@ func TestImportTxSemanticVerify(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: [32]byte{ + TxID: ids.ID{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, @@ -293,7 +293,7 @@ func TestNewImportTx(t *testing.T) { importAmount := uint64(1000000) utxoID := avax.UTXOID{ - TxID: [32]byte{ + TxID: ids.ID{ 0x0f, 0x2f, 0x4f, 0x6f, 0x8e, 0xae, 0xce, 0xee, 0x0d, 0x2d, 0x4d, 0x6d, 0x8c, 0xac, 0xcc, 0xec, 0x0b, 0x2b, 0x4b, 0x6b, 0x8a, 0xaa, 0xca, 0xea, diff --git a/plugin/evm/service.go b/plugin/evm/service.go index c0106ab..65ef3a2 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -24,7 +24,7 @@ import ( ) const ( - version = "coreth" + version = "coreth-v0.3.14" ) // test constants diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index d58fdda..020b663 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -23,14 +23,14 @@ import ( var ( testNetworkID uint32 = 10 - testCChainID = ids.ID([32]byte{'c', 'c', 'h', 'a', 'i', 'n', 't', 'e', 's', 't'}) - testXChainID = ids.ID([32]byte{'t', 'e', 's', 't', 'x'}) - nonExistentID = ids.ID([32]byte{'F'}) + testCChainID = ids.ID{'c', 'c', 'h', 'a', 'i', 'n', 't', 'e', 's', 't'} + testXChainID = ids.ID{'t', 'e', 's', 't', 'x'} + nonExistentID = ids.ID{'F'} testTxFee = uint64(1000) testKeys []*crypto.PrivateKeySECP256K1R testEthAddrs []common.Address // testEthAddrs[i] corresponds to testKeys[i] testShortIDAddrs []ids.ShortID - testAvaxAssetID = [32]byte{1, 2, 3} + testAvaxAssetID = ids.ID{1, 2, 3} username = "Johns" password = "CjasdjhiPeirbSenfeI13" // #nosec G101 ) -- cgit v1.2.3-70-g09d2