diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-09 06:07:44 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-14 06:26:07 +0800 |
commit | a91908e5678397a466060aa614081974a4a36455 (patch) | |
tree | 978be70e63397722f6bec971f045418096995fab /tests/transaction_test_util.go | |
parent | ae33883c2fd72b960e774833708deb1ce10e3fe4 (diff) | |
download | go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar.gz go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar.bz2 go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar.lz go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar.xz go-tangerine-a91908e5678397a466060aa614081974a4a36455.tar.zst go-tangerine-a91908e5678397a466060aa614081974a4a36455.zip |
tests: updated
Diffstat (limited to 'tests/transaction_test_util.go')
-rw-r--r-- | tests/transaction_test_util.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/tests/transaction_test_util.go b/tests/transaction_test_util.go index 184bdee2a..678513e11 100644 --- a/tests/transaction_test_util.go +++ b/tests/transaction_test_util.go @@ -50,7 +50,7 @@ type TransactionTest struct { Transaction TtTransaction } -func RunTransactionTestsWithReader(r io.Reader, skipTests []string) error { +func RunTransactionTestsWithReader(config *params.ChainConfig, r io.Reader, skipTests []string) error { skipTest := make(map[string]bool, len(skipTests)) for _, name := range skipTests { skipTest[name] = true @@ -68,7 +68,7 @@ func RunTransactionTestsWithReader(r io.Reader, skipTests []string) error { return nil } // test the block - if err := runTransactionTest(test); err != nil { + if err := runTransactionTest(config, test); err != nil { return err } glog.Infoln("Transaction test passed: ", name) @@ -77,19 +77,19 @@ func RunTransactionTestsWithReader(r io.Reader, skipTests []string) error { return nil } -func RunTransactionTests(file string, skipTests []string) error { +func RunTransactionTests(config *params.ChainConfig, file string, skipTests []string) error { tests := make(map[string]TransactionTest) if err := readJsonFile(file, &tests); err != nil { return err } - if err := runTransactionTests(tests, skipTests); err != nil { + if err := runTransactionTests(config, tests, skipTests); err != nil { return err } return nil } -func runTransactionTests(tests map[string]TransactionTest, skipTests []string) error { +func runTransactionTests(config *params.ChainConfig, tests map[string]TransactionTest, skipTests []string) error { skipTest := make(map[string]bool, len(skipTests)) for _, name := range skipTests { skipTest[name] = true @@ -103,7 +103,7 @@ func runTransactionTests(tests map[string]TransactionTest, skipTests []string) e } // test the block - if err := runTransactionTest(test); err != nil { + if err := runTransactionTest(config, test); err != nil { return fmt.Errorf("%s: %v", name, err) } glog.Infoln("Transaction test passed: ", name) @@ -112,7 +112,7 @@ func runTransactionTests(tests map[string]TransactionTest, skipTests []string) e return nil } -func runTransactionTest(txTest TransactionTest) (err error) { +func runTransactionTest(config *params.ChainConfig, txTest TransactionTest) (err error) { tx := new(types.Transaction) err = rlp.DecodeBytes(mustConvertBytes(txTest.Rlp), tx) @@ -126,7 +126,7 @@ func runTransactionTest(txTest TransactionTest) (err error) { } } - validationError := verifyTxFields(txTest, tx) + validationError := verifyTxFields(config, txTest, tx) if txTest.Sender == "" { if validationError != nil { // RLP decoding works but validation should fail (test OK) @@ -150,7 +150,7 @@ func runTransactionTest(txTest TransactionTest) (err error) { return errors.New("Should not happen: verify RLP decoding and field validation") } -func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err error) { +func verifyTxFields(chainConfig *params.ChainConfig, txTest TransactionTest, decodedTx *types.Transaction) (err error) { defer func() { if recovered := recover(); recovered != nil { buf := make([]byte, 64<<10) @@ -161,7 +161,6 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e var decodedSender common.Address - chainConfig := ¶ms.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock} signer := types.MakeSigner(chainConfig, common.String2Big(txTest.Blocknumber)) decodedSender, err = types.Sender(signer, decodedTx) if err != nil { @@ -170,7 +169,7 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e expectedSender := mustConvertAddress(txTest.Sender) if expectedSender != decodedSender { - return fmt.Errorf("Sender mismatch: %v %v", expectedSender, decodedSender) + return fmt.Errorf("Sender mismatch: %x %x", expectedSender, decodedSender) } expectedData := mustConvertBytes(txTest.Transaction.Data) @@ -193,7 +192,7 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e return fmt.Errorf("Nonce mismatch: %v %v", expectedNonce, decodedTx.Nonce()) } - v, r, s := types.SignatureValues(signer, decodedTx) + v, r, s := decodedTx.RawSignatureValues() expectedR := mustConvertBigInt(txTest.Transaction.R, 16) if r.Cmp(expectedR) != 0 { return fmt.Errorf("R mismatch: %v %v", expectedR, r) @@ -202,8 +201,8 @@ func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err e if s.Cmp(expectedS) != 0 { return fmt.Errorf("S mismatch: %v %v", expectedS, s) } - expectedV := mustConvertUint(txTest.Transaction.V, 16) - if uint64(v) != expectedV { + expectedV := mustConvertBigInt(txTest.Transaction.V, 16) + if v.Cmp(expectedV) != 0 { return fmt.Errorf("V mismatch: %v %v", expectedV, v) } |