Extract transaction senders from GeneralStateTest fixtures

This commit is contained in:
Dustin Brody 2018-09-05 16:48:06 -07:00 committed by zah
parent 311481359e
commit 9e1be6438e
2 changed files with 41 additions and 6 deletions

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
constants, errors, eth_common, eth_keys, rlp
constants, errors, eth_common, eth_keys, nimcrypto, rlp
proc intrinsicGas*(t: Transaction): GasInt =
# Compute the baseline gas cost for this transaction. This is the amount
@ -21,8 +21,8 @@ proc validate*(t: Transaction) =
raise newException(ValidationError, "Insufficient gas")
# self.check_signature_validity()
func hash*(transaction: Transaction): Hash256 =
# Hash transaction without signature
func rlpEncode*(transaction: Transaction): auto =
# Encode transaction without signature
type
TransHashObj = object
accountNonce: AccountNonce
@ -31,14 +31,18 @@ func hash*(transaction: Transaction): Hash256 =
to: EthAddress
value: UInt256
payload: Blob
return TransHashObj(
return rlp.encode(TransHashObj(
accountNonce: transaction.accountNonce,
gasPrice: transaction.gasPrice,
gasLimit: transaction.gasLimit,
to: transaction.to,
value: transaction.value,
payload: transaction.payload
).rlpHash
))
func hash*(transaction: Transaction): Hash256 =
# Hash transaction without signature
return keccak256.digest(transaction.rlpEncode.toOpenArray)
proc toSignature*(transaction: Transaction): Signature =
var bytes: array[65, byte]

View File

@ -15,7 +15,7 @@ import
type
Status* {.pure.} = enum OK, Fail, Skip
proc validTest*(folder: string, name: string): bool =
func validTest*(folder: string, name: string): bool =
# tests we want to skip or which segfault will be skipped here
result = (folder != "vmPerformance" or "loop" notin name) and
@ -135,3 +135,34 @@ proc getHexadecimalInt*(j: JsonNode): int64 =
var data: StUInt[64]
data = fromHex(StUInt[64], j.getStr)
result = cast[int64](data)
proc getFixtureTransaction*(j: JsonNode): Transaction =
var transaction : Transaction
transaction.accountNonce = j["nonce"].getStr.parseHexInt.AccountNonce
transaction.gasPrice = j["gasPrice"].getStr.parseHexInt
transaction.gasLimit = j["gasLimit"][0].getStr.parseHexInt
transaction.to = j["to"].getStr.parseAddress
transaction.value = j["value"][0].getStr.parseHexInt.u256
# Another, slightly distinct, case of this "" as special-cased hex string
# One possibility's a string prefix func which adds only if 0x is missing
# which can be used across the various hex-string-parsing utility funcs.
let rawData = j["data"][0].getStr
transaction.payload = (if rawData == "": "0x" else: rawData).hexToSeqByte
return transaction
proc getFixtureTransactionSender*(j: JsonNode): auto =
var secretKey = j["secretKey"].getStr
removePrefix(secretKey, "0x")
let privateKey = initPrivateKey(secretKey)
var pubKey: PublicKey
let transaction = j.getFixtureTransaction
if recoverSignatureKey(signMessage(privateKey, transaction.rlpEncode.toOpenArray),
transaction.hash.data,
pubKey) == EthKeysStatus.Success:
return pubKey.toCanonicalAddress()
else:
# XXX: appropriate failure mode; probably raise something
discard