mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-02 23:35:31 +00:00
Extract transaction senders from GeneralStateTest fixtures
This commit is contained in:
parent
311481359e
commit
9e1be6438e
@ -6,7 +6,7 @@
|
|||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
constants, errors, eth_common, eth_keys, rlp
|
constants, errors, eth_common, eth_keys, nimcrypto, rlp
|
||||||
|
|
||||||
proc intrinsicGas*(t: Transaction): GasInt =
|
proc intrinsicGas*(t: Transaction): GasInt =
|
||||||
# Compute the baseline gas cost for this transaction. This is the amount
|
# 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")
|
raise newException(ValidationError, "Insufficient gas")
|
||||||
# self.check_signature_validity()
|
# self.check_signature_validity()
|
||||||
|
|
||||||
func hash*(transaction: Transaction): Hash256 =
|
func rlpEncode*(transaction: Transaction): auto =
|
||||||
# Hash transaction without signature
|
# Encode transaction without signature
|
||||||
type
|
type
|
||||||
TransHashObj = object
|
TransHashObj = object
|
||||||
accountNonce: AccountNonce
|
accountNonce: AccountNonce
|
||||||
@ -31,14 +31,18 @@ func hash*(transaction: Transaction): Hash256 =
|
|||||||
to: EthAddress
|
to: EthAddress
|
||||||
value: UInt256
|
value: UInt256
|
||||||
payload: Blob
|
payload: Blob
|
||||||
return TransHashObj(
|
return rlp.encode(TransHashObj(
|
||||||
accountNonce: transaction.accountNonce,
|
accountNonce: transaction.accountNonce,
|
||||||
gasPrice: transaction.gasPrice,
|
gasPrice: transaction.gasPrice,
|
||||||
gasLimit: transaction.gasLimit,
|
gasLimit: transaction.gasLimit,
|
||||||
to: transaction.to,
|
to: transaction.to,
|
||||||
value: transaction.value,
|
value: transaction.value,
|
||||||
payload: transaction.payload
|
payload: transaction.payload
|
||||||
).rlpHash
|
))
|
||||||
|
|
||||||
|
func hash*(transaction: Transaction): Hash256 =
|
||||||
|
# Hash transaction without signature
|
||||||
|
return keccak256.digest(transaction.rlpEncode.toOpenArray)
|
||||||
|
|
||||||
proc toSignature*(transaction: Transaction): Signature =
|
proc toSignature*(transaction: Transaction): Signature =
|
||||||
var bytes: array[65, byte]
|
var bytes: array[65, byte]
|
||||||
|
@ -15,7 +15,7 @@ import
|
|||||||
type
|
type
|
||||||
Status* {.pure.} = enum OK, Fail, Skip
|
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
|
# tests we want to skip or which segfault will be skipped here
|
||||||
|
|
||||||
result = (folder != "vmPerformance" or "loop" notin name) and
|
result = (folder != "vmPerformance" or "loop" notin name) and
|
||||||
@ -135,3 +135,34 @@ proc getHexadecimalInt*(j: JsonNode): int64 =
|
|||||||
var data: StUInt[64]
|
var data: StUInt[64]
|
||||||
data = fromHex(StUInt[64], j.getStr)
|
data = fromHex(StUInt[64], j.getStr)
|
||||||
result = cast[int64](data)
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user