Skip to content

Commit

Permalink
add a simple test for privateKeyGen precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
allnil committed Feb 1, 2024
1 parent 3596822 commit be2b0ed
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions suave/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,39 @@ func TestSignMessagePrecompile(t *testing.T) {
require.Equal(t, crypto.PubkeyToAddress(sk.PublicKey), crypto.PubkeyToAddress(*pubKeyRecovered))
}

func TestPrivateKeyGeneratePrecompile(t *testing.T) {
fr := newFramework(t)
defer fr.Close()

// function privateKeyGen() string
args, err := artifacts.SuaveAbi.Methods["privateKeyGen"].Inputs.Pack()
require.NoError(t, err)

gas := hexutil.Uint64(1000000)
var callResult hexutil.Bytes
err = fr.suethSrv.RPCNode().Call(&callResult, "eth_call", setTxArgsDefaults(ethapi.TransactionArgs{
To: &privateKeyGen,
Gas: &gas,
IsConfidential: true,
Data: (*hexutil.Bytes)(&args),
}), "latest")
requireNoRpcError(t, err)

// Unpack the call result to get the result of privateKeyGen call
unpackedCallResult, err := artifacts.SuaveAbi.Methods["privateKeyGen"].Outputs.Unpack(callResult)
require.NoError(t, err)

// Get the generated private key
skGenerated := unpackedCallResult[0].(string)
require.NoError(t, err)

// Some tests on key validity
skBytes, err := hex.DecodeString(skGenerated)
require.NoError(t, err)
_, err = crypto.ToECDSA(skBytes)
require.NoError(t, err)
}

type HintEvent struct {
BidId [16]uint8 `abi:"dataId"`
Hint []byte `abi:"hint"`
Expand Down Expand Up @@ -1479,11 +1512,14 @@ var (
fetchBidsAddress = common.HexToAddress("0x42030001")
fillMevShareBundleAddress = common.HexToAddress("0x43200001")

signEthTransaction = common.HexToAddress("0x40100001")
signMessage = common.HexToAddress("0x40100003")
signEthTransaction = common.HexToAddress("0x40100001")
signMessage = common.HexToAddress("0x40100003")

simulateBundleAddress = common.HexToAddress("0x42100000")
buildEthBlockAddress = common.HexToAddress("0x42100001")

privateKeyGen = common.HexToAddress("0x53200003")

/* contracts */
newBundleBidAddress = common.HexToAddress("0x642300000")
newBlockBidAddress = common.HexToAddress("0x642310000")
Expand Down

0 comments on commit be2b0ed

Please sign in to comment.