mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 13:24:21 +00:00
fixes clique signerFn return type
and also add test related to this signerFn
This commit is contained in:
parent
18b26a0089
commit
c99153df22
@ -41,11 +41,13 @@ when enableCliqueAsyncLock:
|
|||||||
import chronos
|
import chronos
|
||||||
|
|
||||||
type
|
type
|
||||||
|
RawSignature* = array[RawSignatureSize, byte]
|
||||||
|
|
||||||
# clique/clique.go(142): type SignerFn func(signer [..]
|
# clique/clique.go(142): type SignerFn func(signer [..]
|
||||||
CliqueSignerFn* = ## Hashes and signs the data to be signed by
|
CliqueSignerFn* = ## Hashes and signs the data to be signed by
|
||||||
## a backing account
|
## a backing account
|
||||||
proc(signer: EthAddress;
|
proc(signer: EthAddress;
|
||||||
message: openArray[byte]): Result[Hash256,cstring] {.gcsafe.}
|
message: openArray[byte]): Result[RawSignature, cstring] {.gcsafe.}
|
||||||
|
|
||||||
Proposals = Table[EthAddress,bool]
|
Proposals = Table[EthAddress,bool]
|
||||||
|
|
||||||
|
@ -9,12 +9,20 @@
|
|||||||
# according to those terms.
|
# according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, os, sequtils, strformat, strutils, times],
|
std/[algorithm, os, sequtils, strformat,
|
||||||
|
strutils, times, parseopt, tables],
|
||||||
../nimbus/db/db_chain,
|
../nimbus/db/db_chain,
|
||||||
../nimbus/p2p/[chain, clique, clique/clique_snapshot],
|
../nimbus/p2p/[chain,
|
||||||
|
clique,
|
||||||
|
clique/clique_snapshot,
|
||||||
|
clique/clique_desc,
|
||||||
|
clique/clique_helpers
|
||||||
|
],
|
||||||
|
../nimbus/utils/ec_recover,
|
||||||
|
../nimbus/[config, utils, constants],
|
||||||
./test_clique/[pool, undump],
|
./test_clique/[pool, undump],
|
||||||
eth/[common, keys],
|
eth/[common, keys],
|
||||||
stint,
|
stint, stew/byteutils,
|
||||||
unittest2
|
unittest2
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -229,6 +237,45 @@ proc runGoerliBaybySteps(noisy = true;
|
|||||||
test &"Runner stopped after reaching #{stopThreshold}":
|
test &"Runner stopped after reaching #{stopThreshold}":
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc cliqueMiscTests() =
|
||||||
|
suite "clique misc":
|
||||||
|
test "signer func":
|
||||||
|
const
|
||||||
|
engineSigner = "658bdf435d810c91414ec09147daa6db62406379"
|
||||||
|
privateKey = "tests" / "test_clique" / "private.key"
|
||||||
|
|
||||||
|
var msg: string
|
||||||
|
var opt = initOptParser("--engine-signer:$1 --import-key:$2" % [engineSigner, privateKey])
|
||||||
|
let res = processArguments(msg, opt)
|
||||||
|
check res == Success
|
||||||
|
let signer = hexToByteArray[20](engineSigner)
|
||||||
|
let conf = getConfiguration()
|
||||||
|
check signer in conf.accounts
|
||||||
|
|
||||||
|
proc signFunc(signer: EthAddress, message: openArray[byte]): Result[RawSignature, cstring] {.gcsafe.} =
|
||||||
|
let
|
||||||
|
hashData = keccakHash(message)
|
||||||
|
conf = getConfiguration()
|
||||||
|
acc = conf.accounts[signer]
|
||||||
|
rawSign = sign(acc.privateKey, SkMessage(hashData.data)).toRaw
|
||||||
|
|
||||||
|
ok(rawSign)
|
||||||
|
|
||||||
|
let signerFn: CliqueSignerFn = signFunc
|
||||||
|
var header: BlockHeader
|
||||||
|
header.extraData.setLen(EXTRA_VANITY)
|
||||||
|
header.extraData.add 0.byte.repeat(EXTRA_SEAL)
|
||||||
|
|
||||||
|
let signature = signerFn(signer, header.encodeSealHeader).get()
|
||||||
|
let extraLen = header.extraData.len
|
||||||
|
if EXTRA_SEAL < extraLen:
|
||||||
|
header.extraData.setLen(extraLen - EXTRA_SEAL)
|
||||||
|
header.extraData.add signature
|
||||||
|
|
||||||
|
let resAddr = ecRecover(header)
|
||||||
|
check resAddr.isOk
|
||||||
|
check resAddr.value == signer
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Main function(s)
|
# Main function(s)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -238,6 +285,7 @@ proc cliqueMain*(noisy = defined(debug)) =
|
|||||||
noisy.runCliqueSnapshot(false)
|
noisy.runCliqueSnapshot(false)
|
||||||
noisy.runGoerliBaybySteps
|
noisy.runGoerliBaybySteps
|
||||||
noisy.runGoerliReplay(startAtBlock = 31100u64)
|
noisy.runGoerliReplay(startAtBlock = 31100u64)
|
||||||
|
cliqueMiscTests()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let
|
let
|
||||||
@ -257,13 +305,14 @@ when isMainModule:
|
|||||||
dir = dir, captureFile = captureFile,
|
dir = dir, captureFile = captureFile,
|
||||||
startAtBlock = startAtBlock, stopAfterBlock = stopAfterBlock)
|
startAtBlock = startAtBlock, stopAfterBlock = stopAfterBlock)
|
||||||
|
|
||||||
let noisy = defined(debug)
|
#[let noisy = defined(debug)
|
||||||
noisy.runCliqueSnapshot(true)
|
noisy.runCliqueSnapshot(true)
|
||||||
noisy.runCliqueSnapshot(false)
|
noisy.runCliqueSnapshot(false)
|
||||||
noisy.runGoerliBaybySteps(dir = ".")
|
noisy.runGoerliBaybySteps(dir = ".")
|
||||||
noisy.runGoerliReplay(dir = ".", startAtBlock = 31100u64)
|
noisy.runGoerliReplay(dir = ".", startAtBlock = 31100u64)]#
|
||||||
#noisy.goerliReplay(startAtBlock = 31100u64)
|
#noisy.goerliReplay(startAtBlock = 31100u64)
|
||||||
#noisy.goerliReplay(startAtBlock = 194881u64, stopAfterBlock = 198912u64)
|
#noisy.goerliReplay(startAtBlock = 194881u64, stopAfterBlock = 198912u64)
|
||||||
|
cliqueMiscTests()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
1
tests/test_clique/private.key
Normal file
1
tests/test_clique/private.key
Normal file
@ -0,0 +1 @@
|
|||||||
|
9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c
|
Loading…
x
Reference in New Issue
Block a user