@@ -23,7 +23,6 @@ import (
2323 "github.com/ethereum/go-ethereum/common"
2424 "github.com/ethereum/go-ethereum/core/types"
2525 hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
26- "github.com/stretchr/testify/assert"
2726 "github.com/stretchr/testify/require"
2827
2928 "perun.network/go-perun/backend/ethereum/channel/test"
@@ -38,24 +37,58 @@ const missingAddr = "0x1"
3837// noSignHash is used to hide the SignHash function of the embedded wallet.
3938type noSignHash struct {
4039 * hdwallet.Wallet
41- SignTxCalled bool
4240}
4341
4442func TestTransactor (t * testing.T ) {
4543 rng := pkgtest .Prng (t )
46- // The normal transactor should be able to deal with all signers.
47- s := newTransactorSetup (t , rng , false )
48- test .GenericLegacyTransactorTest (t , rng , s )
49- test .GenericEIP155TransactorTest (t , rng , s )
44+ chainID := rng .Int63 ()
5045
51- // The noSignHasher should only work with Frontier and Homestead.
52- s = newTransactorSetup (t , rng , true )
53- test .GenericLegacyTransactorTest (t , rng , s )
54- assert .True (t , s .Tr .(* hd.Transactor ).Wallet .(* noSignHash ).SignTxCalled )
46+ tests := []struct {
47+ title string
48+ signer types.Signer
49+ chainID int64
50+ hideSignHash bool
51+ }{
52+ {
53+ title : "FrontierSigner" ,
54+ signer : & types.FrontierSigner {},
55+ chainID : 0 ,
56+ },
57+ {
58+ title : "HomesteadSigner" ,
59+ signer : & types.HomesteadSigner {},
60+ chainID : 0 ,
61+ },
62+ {
63+ title : "FrontierSigner (hideSignHash)" ,
64+ signer : & types.FrontierSigner {},
65+ chainID : 0 ,
66+ hideSignHash : true ,
67+ },
68+ {
69+ title : "HomesteadSigner (hideSignHash)" ,
70+ signer : & types.HomesteadSigner {},
71+ chainID : 0 ,
72+ hideSignHash : true ,
73+ },
74+ {
75+ title : "EIP155Signer" ,
76+ signer : types .NewEIP155Signer (big .NewInt (chainID )),
77+ chainID : chainID ,
78+ },
79+ }
80+
81+ for _ , _t := range tests {
82+ _t := _t
83+ t .Run (_t .title , func (t * testing.T ) {
84+ s := newTransactorSetup (t , rng , _t .hideSignHash , _t .signer , _t .chainID )
85+ test .GenericSignerTest (t , rng , s )
86+ })
87+ }
5588}
5689
5790// nolint:interfacer // rand.Rand is preferred over io.Reader here.
58- func newTransactorSetup (t * testing.T , prng * rand.Rand , hideSignHash bool ) test.TransactorSetup {
91+ func newTransactorSetup (t * testing.T , prng * rand.Rand , hideSignHash bool , signer types. Signer , chainID int64 ) test.TransactorSetup {
5992 walletSeed := make ([]byte , 20 )
6093 prng .Read (walletSeed )
6194 mnemonic , err := hdwallet .NewMnemonicFromEntropy (walletSeed )
@@ -67,7 +100,7 @@ func newTransactorSetup(t *testing.T, prng *rand.Rand, hideSignHash bool) test.T
67100
68101 var wrappedWallet accounts.Wallet = rawHDWallet
69102 if hideSignHash {
70- wrappedWallet = & noSignHash {rawHDWallet , false }
103+ wrappedWallet = & noSignHash {rawHDWallet }
71104 }
72105 hdWallet , err := hd .NewWallet (wrappedWallet , hd .DefaultRootDerivationPath .String (), 0 )
73106 require .NoError (t , err )
@@ -78,7 +111,9 @@ func newTransactorSetup(t *testing.T, prng *rand.Rand, hideSignHash bool) test.T
78111 require .NotNil (t , validAcc )
79112
80113 return test.TransactorSetup {
81- Tr : hd .NewTransactor (hdWallet .Wallet ()),
114+ Signer : signer ,
115+ ChainID : chainID ,
116+ Tr : hd .NewTransactor (hdWallet .Wallet (), signer ),
82117 ValidAcc : accounts.Account {Address : wallet .AsEthAddr (validAcc .Address ())},
83118 MissingAcc : accounts.Account {Address : common .HexToAddress (missingAddr )},
84119 }
@@ -87,9 +122,3 @@ func newTransactorSetup(t *testing.T, prng *rand.Rand, hideSignHash bool) test.T
87122// SignHash hides the public SignHash.
88123func (* noSignHash ) SignHash () {
89124}
90-
91- // SignTx calls SignTx of the embedded wallet and sets SignTxCalled to true.
92- func (n * noSignHash ) SignTx (account accounts.Account , tx * types.Transaction , chainID * big.Int ) (* types.Transaction , error ) {
93- n .SignTxCalled = true
94- return n .Wallet .SignTx (account , tx , chainID )
95- }
0 commit comments