From 04271a89fe84fa7d90fe81a506f7e520e8e9d039 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 16 Jan 2018 11:56:21 -0600 Subject: [PATCH] sharding transaction tests Former-commit-id: 05978a0028b27bc99cdbd2cdf8f66c78a48444be [formerly c05cd8f789a0f2a3b24b4a41eda2d6d89c33e41b] Former-commit-id: 04955bc0a35f4932b5ff28c98393ff79d0356d4a --- sharding/transactions.go | 8 ++++---- sharding/transactions_test.go | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/sharding/transactions.go b/sharding/transactions.go index 77a1c0191..14e8731eb 100644 --- a/sharding/transactions.go +++ b/sharding/transactions.go @@ -33,7 +33,7 @@ type txdata struct { // Sharding specific fields // TODO: Figure out exact format of accesslist. array of arrays of addr + prefixes? - AccessList []*common.Address `json:"accessList" gencodec:"required"` + AccessList []common.Address `json:"accessList" gencodec:"required"` // This is only used when marshaling to JSON. Hash *common.Hash `json:"hash" rlp:"-"` @@ -49,15 +49,15 @@ type txdataMarshaling struct { ShardID hexutil.Uint64 } -func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { return newShardingTransaction(nonce, &to, amount, gasLimit, gasPrice, data, accessList) } -func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { return newShardingTransaction(nonce, nil, amount, gasLimit, gasPrice, data, accessList) } -func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { if len(data) > 0 { data = common.CopyBytes(data) } diff --git a/sharding/transactions_test.go b/sharding/transactions_test.go index dc7b45594..3c53d9476 100644 --- a/sharding/transactions_test.go +++ b/sharding/transactions_test.go @@ -5,11 +5,33 @@ import ( //"fmt" //"math/rand" //"os" + "github.com/ethereum/go-ethereum/common" + "math/big" "testing" ) +var ( + txSimple = NewShardingTransaction( + 0, + common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), + // amount + big.NewInt(10), + // gasLimit + 1000000, + // gasPrice + big.NewInt(1), + // data + common.FromHex("hello world this is the data"), + // access list + []common.Address{common.HexToAddress("032e7baea6a6c7c4c2dfe98392932326af552d87"), common.HexToAddress("083e7baea6a6c7c4c2dfeb97710293843f552d87")}, + ) +) + func TestCreation(t *testing.T) { - if 1 != 2 { - t.Fatalf("Values are not equal") + if txSimple.ChainID().Cmp(big.NewInt(1)) != 0 { + t.Fatalf("ChainID invalid") + } + if txSimple.ShardID().Cmp(big.NewInt(1)) != 0 { + t.Fatalf("ShardID invalid") } }