diff --git a/backend/ethereum/wallet/hd/wallet_test.go b/backend/ethereum/wallet/hd/wallet_test.go index 5ad8c9413..4280a450a 100644 --- a/backend/ethereum/wallet/hd/wallet_test.go +++ b/backend/ethereum/wallet/hd/wallet_test.go @@ -129,6 +129,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, accounts.Wallet AddressInWallet: acc.Address(), Backend: new(ethwallet.Backend), AddressEncoded: sampleBytes, + ZeroAddress: ethwallet.AsWalletAddr(common.Address{}), DataToSign: dataToSign, }, rawHDWallet, hdWallet } diff --git a/backend/ethereum/wallet/keystore/wallet_test.go b/backend/ethereum/wallet/keystore/wallet_test.go index 66d71f3a4..4e72bf8fe 100644 --- a/backend/ethereum/wallet/keystore/wallet_test.go +++ b/backend/ethereum/wallet/keystore/wallet_test.go @@ -94,6 +94,7 @@ func newSetup(t require.TestingT) *test.Setup { AddressInWallet: acc.Address(), Backend: new(ethwallet.Backend), AddressEncoded: validAddrBytes, + ZeroAddress: ethwallet.AsWalletAddr(common.Address{}), DataToSign: dataToSign, } } diff --git a/backend/ethereum/wallet/simple/wallet_test.go b/backend/ethereum/wallet/simple/wallet_test.go index dd51e29f7..9d29a4c19 100644 --- a/backend/ethereum/wallet/simple/wallet_test.go +++ b/backend/ethereum/wallet/simple/wallet_test.go @@ -110,6 +110,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, *simple.Wallet) AddressInWallet: acc.Address(), Backend: new(ethwallet.Backend), AddressEncoded: validAddrBytes, + ZeroAddress: ethwallet.AsWalletAddr(common.Address{}), DataToSign: dataToSign, }, simpleWallet } diff --git a/backend/sim/wallet/wallet_internal_test.go b/backend/sim/wallet/wallet_internal_test.go index 3a4a346b0..d0b8f7130 100644 --- a/backend/sim/wallet/wallet_internal_test.go +++ b/backend/sim/wallet/wallet_internal_test.go @@ -15,6 +15,7 @@ package wallet import ( + "bytes" "math/big" "math/rand" "testing" @@ -99,11 +100,20 @@ func newWalletSetup(rng *rand.Rand) *test.Setup { panic(err) } + backend := new(Backend) + addrEncoded := accountB.Address().Bytes() + addrLen := len(addrEncoded) + zeroAddr, err := backend.DecodeAddress(bytes.NewReader(make([]byte, addrLen))) + if err != nil { + panic(err) + } + return &test.Setup{ - Backend: new(Backend), + Backend: backend, Wallet: w, AddressInWallet: acc.Address(), - AddressEncoded: accountB.Address().Bytes(), + AddressEncoded: addrEncoded, + ZeroAddress: zeroAddr, DataToSign: data, } } diff --git a/wallet/test/address.go b/wallet/test/address.go index e94f6d0a9..6fefe6a89 100644 --- a/wallet/test/address.go +++ b/wallet/test/address.go @@ -25,9 +25,7 @@ import ( // TestAddress runs a test suite designed to test the general functionality of // an address implementation. func TestAddress(t *testing.T, s *Setup) { - addrLen := len(s.AddressEncoded) - null, err := s.Backend.DecodeAddress(bytes.NewReader(make([]byte, addrLen))) - assert.NoError(t, err, "Byte deserialization of zero address should work") + null := s.ZeroAddress addr, err := s.Backend.DecodeAddress(bytes.NewReader(s.AddressEncoded)) assert.NoError(t, err, "Byte deserialization of address should work") @@ -42,6 +40,11 @@ func TestAddress(t *testing.T, s *Setup) { assert.False(t, addr.Equals(null), "Expected inequality of zero, nonzero address") assert.True(t, null.Equals(null), "Expected equality of zero address to itself") + // Test Address.Cmp. + assert.Positive(t, addr.Cmp(null), "Expected addr > zero") + assert.Zero(t, null.Cmp(null), "Expected zero = zero") + assert.Negative(t, null.Cmp(addr), "Expected null < addr") + // Test Address.Bytes. addrBytes := addr.Bytes() nullBytes := null.Bytes() diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 82d7f33af..14de689bf 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -35,6 +35,7 @@ type Setup struct { Backend wallet.Backend // backend implementation Wallet wallet.Wallet // the wallet instance used for testing AddressInWallet wallet.Address // an address of an account in the test wallet + ZeroAddress wallet.Address // an address that is less or equal to any other address DataToSign []byte // some data to sign AddressEncoded []byte // a valid nonzero address not in the wallet }