github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/utils/signers/internaltx/internaltx_test.go (about) 1 package internaltx 2 3 import ( 4 "math/big" 5 "testing" 6 7 "github.com/status-im/keycard-go/hexutils" 8 "github.com/stretchr/testify/require" 9 "github.com/unicornultrafoundation/go-u2u/common" 10 "github.com/unicornultrafoundation/go-u2u/core/types" 11 ) 12 13 func TestIsInternal(t *testing.T) { 14 require.True(t, IsInternal(types.NewTx(&types.LegacyTx{ 15 V: new(big.Int), 16 R: new(big.Int), 17 S: new(big.Int), 18 }))) 19 require.True(t, IsInternal(types.NewTx(&types.DynamicFeeTx{ 20 V: new(big.Int), 21 R: new(big.Int), 22 S: new(big.Int), 23 }))) 24 require.True(t, IsInternal(types.NewTx(&types.LegacyTx{ 25 V: new(big.Int), 26 R: new(big.Int), 27 S: big.NewInt(1), 28 }))) 29 require.True(t, IsInternal(types.NewTx(&types.LegacyTx{ 30 V: new(big.Int), 31 R: new(big.Int), 32 S: new(big.Int).SetBytes(hexutils.HexToBytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), 33 }))) 34 require.False(t, IsInternal(types.NewTx(&types.LegacyTx{ 35 V: big.NewInt(1), 36 R: big.NewInt(1), 37 S: big.NewInt(1), 38 }))) 39 require.False(t, IsInternal(types.NewTx(&types.DynamicFeeTx{ 40 V: big.NewInt(1), 41 R: big.NewInt(1), 42 S: big.NewInt(1), 43 }))) 44 require.False(t, IsInternal(types.NewTx(&types.LegacyTx{ 45 V: big.NewInt(1), 46 R: new(big.Int), 47 S: new(big.Int), 48 }))) 49 require.False(t, IsInternal(types.NewTx(&types.LegacyTx{ 50 V: new(big.Int), 51 R: big.NewInt(1), 52 S: new(big.Int), 53 }))) 54 } 55 56 func TestInternalSender(t *testing.T) { 57 require.Equal(t, common.Address{}, InternalSender(types.NewTx(&types.LegacyTx{ 58 V: new(big.Int), 59 R: new(big.Int), 60 S: new(big.Int), 61 }))) 62 example := common.HexToAddress("0x0000000000000000000000000000000000000001") 63 require.Equal(t, example, InternalSender(types.NewTx(&types.LegacyTx{ 64 V: new(big.Int), 65 R: new(big.Int), 66 S: new(big.Int).SetBytes(example.Bytes()), 67 }))) 68 example = common.HexToAddress("0x0000000000000000000000000000000000000100") 69 require.Equal(t, example, InternalSender(types.NewTx(&types.LegacyTx{ 70 V: new(big.Int), 71 R: new(big.Int), 72 S: new(big.Int).SetBytes(example.Bytes()), 73 }))) 74 example = common.HexToAddress("0x1000000000000000000000000000000000000000") 75 require.Equal(t, example, InternalSender(types.NewTx(&types.LegacyTx{ 76 V: new(big.Int), 77 R: new(big.Int), 78 S: new(big.Int).SetBytes(example.Bytes()), 79 }))) 80 example = common.HexToAddress("0x1000000000000000000000000000000000000001") 81 require.Equal(t, example, InternalSender(types.NewTx(&types.LegacyTx{ 82 V: new(big.Int), 83 R: new(big.Int), 84 S: new(big.Int).SetBytes(example.Bytes()), 85 }))) 86 }