gst refactor: share the same tx.getSender with rest of Nimbus

This commit is contained in:
andri lim 2019-03-02 19:05:24 +07:00 committed by zah
parent 4db43dcd7e
commit 38757c956d
2 changed files with 9 additions and 15 deletions

View File

@ -10,7 +10,7 @@ import
byteutils, ranges/typedranges, nimcrypto/[keccak, hash], options,
eth/[rlp, common, keys], eth/trie/db, chronicles,
./test_helpers, ../nimbus/p2p/executor,
../nimbus/[constants, errors],
../nimbus/[constants, errors, transaction],
../nimbus/[vm_state, vm_types, vm_state_transactions, utils],
../nimbus/vm/interpreter,
../nimbus/db/[db_chain, state_db]
@ -24,7 +24,7 @@ suite "generalstate json tests":
jsonTest("GeneralStateTests", testFixture)
proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNode, tx: Transaction,
sender: EthAddress, expectedHash, expectedLogs: string, testStatusIMPL: var TestStatus, fork: Fork) =
expectedHash, expectedLogs: string, testStatusIMPL: var TestStatus, fork: Fork) =
when enabledLogLevel <= TRACE:
let tracerFlags = {TracerFlags.EnableTracing}
else:
@ -42,6 +42,7 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo
let expectedLogsHash = toLowerAscii(expectedLogs)
check(expectedLogsHash == actualLogsHash)
let sender = tx.getSender()
if not validateTransaction(vmState, tx, sender):
vmState.mutateStateDB:
# pre-EIP158 (e.g., Byzantium) should ensure currentCoinbase exists
@ -89,7 +90,5 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
gasIndex = indexes["gas"].getInt
valueIndex = indexes["value"].getInt
let transaction = ftrans.getFixtureTransaction(dataIndex, gasIndex, valueIndex)
let sender = ftrans.getFixtureTransactionSender
testFixtureIndexes(emptyRlpHash, header, fixture["pre"], transaction,
sender, expectedHash, expectedLogs, testStatusIMPL, fork)
expectedHash, expectedLogs, testStatusIMPL, fork)

View File

@ -277,17 +277,12 @@ proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int):
result.value = fromHex(UInt256, j["value"][valueIndex].getStr)
result.payload = j["data"][dataIndex].getStr.safeHexToSeqByte
proc getFixtureTransactionSender*(j: JsonNode): EthAddress =
var secretKey = j["secretKey"].getStr
removePrefix(secretKey, "0x")
let privateKey = initPrivateKey(secretKey)
let sig = signMessage(privateKey, result.rlpEncode)
let raw = sig.getRaw()
var pubKey: PublicKey
let transaction = j.getFixtureTransaction(0, 0, 0)
if recoverSignatureKey(signMessage(privateKey, transaction.rlpEncode),
transaction.txHashNoSignature.data,
pubKey) == EthKeysStatus.Success:
return pubKey.toCanonicalAddress()
else:
# XXX: appropriate failure mode; probably raise something
discard
result.R = fromBytesBE(Uint256, raw[0..31])
result.S = fromBytesBE(Uint256, raw[32..63])
result.V = raw[64] + 27.byte