remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/libs/remix-lib/test/txResultHelper.ts

116 lines
3.3 KiB

'use strict'
import tape from 'tape'
import { BN } from 'bn.js'
8 months ago
import { toBytes } from '@ethereumjs/util'
import { resultToRemixTx } from '../src/helpers/txResultHelper'
const TRANSACTION_HASH = '0x538ad944d09c2df403f064c1e4556fae877fe3f1b600c567622e330c2bdbbe2e'
const CONTRACT_ADDRESS_HEX = '0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
8 months ago
const CONTRACT_ADDRESS_BUFFER = toBytes(
[105, 42, 112, 210, 228, 36, 165, 109, 44, 108, 39, 170, 151, 209, 168,
99, 149, 135, 123, 58])
const RETURN_VALUE_HEX = '0x0000000000000000000000000000000000000000000000000000000000000001'
8 months ago
const RETURN_VALUE_BUFFER = toBytes(
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1])
const STATUS_OK = '0x1'
const GAS_USED_INT = 75427
const GAS_USED_HEX = '0x126a3'
const NODE_CALL_RESULT = {
receipt: {},
result: RETURN_VALUE_HEX,
transactionHash: undefined
}
const NODE_TX_RESULT = {
receipt: {
blockHash: '0x380485a4e6372a42e36489783c7f7cb66257612133cd245859c206fd476e9c44',
blockNumber: 5994,
contractAddress: CONTRACT_ADDRESS_HEX,
cumulativeGasUsed: GAS_USED_INT,
from: '0xed9d02e382b34818e88b88a309c7fe71e65f419d',
gasUsed: GAS_USED_INT,
status: STATUS_OK,
to: null,
transactionHash: TRANSACTION_HASH,
transactionIndex: 0
},
transactionHash: TRANSACTION_HASH
}
const VM_RESULT = {
receipt: {
amountSpent: new BN(1),
contractAddress: CONTRACT_ADDRESS_BUFFER,
gasRefund: new BN(0),
gasUsed: new BN(GAS_USED_INT),
status: STATUS_OK,
},
transactionHash: TRANSACTION_HASH
}
const EXEC_RESULT = {
exceptionError: null,
gasRefund: new BN(0),
gasUsed: new BN(GAS_USED_INT),
returnValue: RETURN_VALUE_BUFFER
}
const EXEC_RESULT_ERROR = {
exceptionError: 'this is an error'
}
tape('converts node transaction result to RemixTx', function (t) {
// contract creation
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const txResult = { ...NODE_TX_RESULT }
let remixTx = resultToRemixTx(txResult, {})
t.equal(remixTx.transactionHash, TRANSACTION_HASH)
t.equal(remixTx.createdAddress, CONTRACT_ADDRESS_HEX)
t.equal(remixTx.status, STATUS_OK)
t.equal(remixTx.gasUsed, GAS_USED_HEX)
t.equal(remixTx.return, undefined)
t.equal(remixTx.error, undefined)
// contract method tx
txResult.receipt.contractAddress = null
remixTx = resultToRemixTx(txResult, {})
t.equal(remixTx.createdAddress, null)
t.end()
})
tape('converts node call result to RemixTx', function (t) {
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const txResult = { ...NODE_CALL_RESULT }
const remixTx = resultToRemixTx(txResult, {})
t.equal(remixTx.transactionHash, undefined)
t.equal(remixTx.createdAddress, undefined)
t.equal(remixTx.status, undefined)
t.equal(remixTx.gasUsed, undefined)
t.equal(remixTx.return, RETURN_VALUE_HEX)
t.equal(remixTx.error, undefined)
t.end()
})
tape('converts VM result to RemixTx', function (t) {
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const txResult = { ...VM_RESULT }
let remixTx = resultToRemixTx(txResult, EXEC_RESULT)
t.equal(remixTx.transactionHash,
TRANSACTION_HASH)
t.equal(remixTx.createdAddress, CONTRACT_ADDRESS_HEX)
t.equal(remixTx.status, STATUS_OK)
t.equal(remixTx.gasUsed, GAS_USED_HEX)
t.equal(remixTx.return, RETURN_VALUE_HEX)
t.equal(remixTx.error, null)
remixTx = resultToRemixTx(VM_RESULT, EXEC_RESULT_ERROR)
t.equal(remixTx.error, 'this is an error')
t.end()
})