@@ -5,9 +5,47 @@ import (
55 "testing"
66
77 "github.com/stretchr/testify/assert"
8+ "github.com/stretchr/testify/require"
89 "github.com/umbracle/ethgo"
10+ "pgregory.net/rapid"
911)
1012
13+ func TestSigner_SignAndRecover (t * testing.T ) {
14+ rapid .Check (t , func (t * rapid.T ) {
15+ istyped := rapid .Bool ().Draw (t , "istyped" )
16+
17+ // fill in common types for a transaction
18+ txn := & ethgo.Transaction {}
19+
20+ if rapid .Bool ().Draw (t , "to" ) {
21+ to := ethgo .BytesToAddress (rapid .SliceOf (rapid .Byte ()).Draw (t , "to_addr" ))
22+ txn .To = & to
23+ }
24+
25+ // fill in specific fields depending on the type
26+ // of the transaction.
27+ if istyped {
28+ txn .Type = ethgo .TransactionAccessList
29+ }
30+
31+ // signer is from a random chain
32+ chainid := rapid .Uint64 ().Draw (t , "chainid" )
33+ signer := NewEIP155Signer (chainid )
34+
35+ key , err := GenerateKey ()
36+ require .NoError (t , err )
37+
38+ signedTxn , err := signer .SignTx (txn , key )
39+ require .NoError (t , err )
40+
41+ // recover the sender
42+ sender , err := signer .RecoverSender (signedTxn )
43+ require .NoError (t , err )
44+
45+ require .Equal (t , sender , key .Address ())
46+ })
47+ }
48+
1149func TestSigner_EIP1155 (t * testing.T ) {
1250 signer1 := NewEIP155Signer (1337 )
1351
@@ -26,14 +64,6 @@ func TestSigner_EIP1155(t *testing.T) {
2664 from , err := signer1 .RecoverSender (txn )
2765 assert .NoError (t , err )
2866 assert .Equal (t , from , key .addr )
29-
30- /*
31- // try to use a signer with another chain id
32- signer2 := NewEIP155Signer(2)
33- from2, err := signer2.RecoverSender(txn)
34- assert.NoError(t, err)
35- assert.NotEqual(t, from, from2)
36- */
3767}
3868
3969func TestTrimBytesZeros (t * testing.T ) {
0 commit comments