diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-26 00:05:29 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-26 00:05:29 +0800 |
commit | 505f1fbcbbc00b3f4750b9e9a7c119f882c620bf (patch) | |
tree | 45b2a6845d6300b4aeea26e3f60b0d5c589fa97e /core/types/transaction_test.go | |
parent | 65ea55bccd8afb94bed540c89e9ce77acbfa3b31 (diff) | |
download | dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar.gz dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar.bz2 dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar.lz dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar.xz dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.tar.zst dexon-505f1fbcbbc00b3f4750b9e9a7c119f882c620bf.zip |
added tx tests and fixed block tests
Diffstat (limited to 'core/types/transaction_test.go')
-rw-r--r-- | core/types/transaction_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 0b0dfe3ff..6a015cb9a 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -2,10 +2,12 @@ package types import ( "bytes" + "crypto/ecdsa" "math/big" "testing" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" ) @@ -56,3 +58,54 @@ func TestTransactionEncode(t *testing.T) { t.Errorf("encoded RLP mismatch, got %x", txb) } } + +func decodeTx(data []byte) (*Transaction, error) { + var tx Transaction + return &tx, rlp.Decode(bytes.NewReader(data), &tx) +} + +func defaultTestKey() (*ecdsa.PrivateKey, []byte) { + key := crypto.ToECDSA(common.Hex2Bytes("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8")) + addr := crypto.PubkeyToAddress(key.PublicKey) + return key, addr +} + +func TestRecipientEmpty(t *testing.T) { + _, addr := defaultTestKey() + + tx, err := decodeTx(common.Hex2Bytes("f8498080808080011ca09b16de9d5bdee2cf56c28d16275a4da68cd30273e2525f3959f5d62557489921a0372ebd8fb3345f7db7b5a86d42e24d36e983e259b0664ceb8c227ec9af572f3d")) + if err != nil { + t.Error(err) + t.FailNow() + } + + from, err := tx.From() + if err != nil { + t.Error(err) + t.FailNow() + } + + if !bytes.Equal(addr, from.Bytes()) { + t.Error("derived address doesn't match") + } +} + +func TestRecipientNormal(t *testing.T) { + _, addr := defaultTestKey() + + tx, err := decodeTx(common.Hex2Bytes("f85d80808094000000000000000000000000000000000000000080011ca0527c0d8f5c63f7b9f41324a7c8a563ee1190bcbf0dac8ab446291bdbf32f5c79a0552c4ef0a09a04395074dab9ed34d3fbfb843c2f2546cc30fe89ec143ca94ca6")) + if err != nil { + t.Error(err) + t.FailNow() + } + + from, err := tx.From() + if err != nil { + t.Error(err) + t.FailNow() + } + + if !bytes.Equal(addr, from.Bytes()) { + t.Error("derived address doesn't match") + } +} |