aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm/export_tx.go
diff options
context:
space:
mode:
authorAaron Buchwald <[email protected]>2020-09-22 16:45:12 -0400
committerAaron Buchwald <[email protected]>2020-09-23 00:33:57 -0400
commita725a6a16c53f508681484e36729ebe65a5b33b1 (patch)
tree23fb875b6f13f3a079c4581a968b46b974b4a153 /plugin/evm/export_tx.go
parent8cc21e15b96ccbe246bb06bece08c22df786069d (diff)
Add test for ExportTx Verify
Diffstat (limited to 'plugin/evm/export_tx.go')
-rw-r--r--plugin/evm/export_tx.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go
index f210352..b76e312 100644
--- a/plugin/evm/export_tx.go
+++ b/plugin/evm/export_tx.go
@@ -56,6 +56,8 @@ func (tx *UnsignedExportTx) Verify(
return errWrongChainID
case !tx.DestinationChain.Equals(avmID):
return errWrongChainID
+ case len(tx.Ins) == 0:
+ return errNoExportInputs
case len(tx.ExportedOutputs) == 0:
return errNoExportOutputs
case tx.NetworkID != ctx.NetworkID:
@@ -69,6 +71,9 @@ func (tx *UnsignedExportTx) Verify(
return err
}
}
+ if !IsSortedAndUniqueEVMInputs(tx.Ins) {
+ return errInputsNotSortedAndUnique
+ }
for _, out := range tx.ExportedOutputs {
if err := out.Verify(); err != nil {
@@ -160,7 +165,7 @@ func (tx *UnsignedExportTx) Accept(ctx *snow.Context, _ database.Batch) error {
return ctx.SharedMemory.Put(tx.DestinationChain, elems)
}
-// Create a new transaction
+// newExportTx returns a new ExportTx
func (vm *VM) newExportTx(
assetID ids.ID, // AssetID of the tokens to export
amount uint64, // Amount of tokens to export
@@ -183,14 +188,14 @@ func (vm *VM) newExportTx(
toBurn = vm.txFee
}
// burn AVAX
- ins, signers, err := vm.GetSpendableCanonical(keys, vm.ctx.AVAXAssetID, toBurn)
+ ins, signers, err := vm.GetSpendableFunds(keys, vm.ctx.AVAXAssetID, toBurn)
if err != nil {
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
// burn non-AVAX
if !assetID.Equals(vm.ctx.AVAXAssetID) {
- ins2, signers2, err := vm.GetSpendableCanonical(keys, assetID, amount)
+ ins2, signers2, err := vm.GetSpendableFunds(keys, assetID, amount)
if err != nil {
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
@@ -210,6 +215,9 @@ func (vm *VM) newExportTx(
},
}}
+ avax.SortTransferableOutputs(exportOuts, vm.codec)
+ SortEVMInputsAndSigners(ins, signers)
+
// Create the transaction
utx := &UnsignedExportTx{
NetworkID: vm.ctx.NetworkID,