diff options
-rw-r--r-- | tests/blocktest.go | 46 | ||||
-rw-r--r-- | tests/transaction_test.go | 29 | ||||
-rw-r--r-- | tests/transaction_test_util.go | 19 |
3 files changed, 53 insertions, 41 deletions
diff --git a/tests/blocktest.go b/tests/blocktest.go index 84b70678d..2d6b11944 100644 --- a/tests/blocktest.go +++ b/tests/blocktest.go @@ -187,9 +187,9 @@ func mustConvertHeader(in btHeader) *types.Header { UncleHash: mustConvertHash(in.UncleHash), ParentHash: mustConvertHash(in.ParentHash), Extra: mustConvertBytes(in.ExtraData), - GasUsed: mustConvertBigInt10(in.GasUsed), - GasLimit: mustConvertBigInt10(in.GasLimit), - Difficulty: mustConvertBigInt10(in.Difficulty), + GasUsed: mustConvertBigInt(in.GasUsed), + GasLimit: mustConvertBigInt(in.GasLimit), + Difficulty: mustConvertBigInt(in.Difficulty), Time: mustConvertUint(in.Timestamp), } // XXX cheats? :-) @@ -211,9 +211,13 @@ func mustConvertBlocks(testBlocks []btBlock) []*types.Block { } func mustConvertBytes(in string) []byte { - out, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) + if in == "0x" { + return []byte{} + } + h := strings.TrimPrefix(unfuckCPPHexInts(in), "0x") + out, err := hex.DecodeString(h) if err != nil { - panic(fmt.Errorf("invalid hex: %q", in)) + panic(fmt.Errorf("invalid hex: %q", h)) } return out } @@ -242,16 +246,8 @@ func mustConvertBloom(in string) types.Bloom { return types.BytesToBloom(out) } -func mustConvertBigInt10(in string) *big.Int { - out, ok := new(big.Int).SetString(in, 10) - if !ok { - panic(fmt.Errorf("invalid integer: %q", in)) - } - return out -} - -func mustConvertBigIntHex(in string) *big.Int { - out, ok := new(big.Int).SetString(in, 16) +func mustConvertBigInt(in string) *big.Int { + out, ok := new(big.Int).SetString(unfuckCPPHexInts(in), 0) if !ok { panic(fmt.Errorf("invalid integer: %q", in)) } @@ -259,15 +255,7 @@ func mustConvertBigIntHex(in string) *big.Int { } func mustConvertUint(in string) uint64 { - out, err := strconv.ParseUint(in, 0, 64) - if err != nil { - panic(fmt.Errorf("invalid integer: %q", in)) - } - return out -} - -func mustConvertUintHex(in string) uint64 { - out, err := strconv.ParseUint(in, 16, 64) + out, err := strconv.ParseUint(unfuckCPPHexInts(in), 0, 64) if err != nil { panic(fmt.Errorf("invalid integer: %q", in)) } @@ -303,3 +291,13 @@ func findLine(data []byte, offset int64) (line int) { } return } + +func unfuckCPPHexInts(s string) string { + if s == "0x" { // no respect for the empty value :( + return "0x00" + } + if (len(s) % 2) != 0 { // motherfucking nibbles + return "0x0" + s[2:] + } + return s +} diff --git a/tests/transaction_test.go b/tests/transaction_test.go index dabc7823b..a6c7492d5 100644 --- a/tests/transaction_test.go +++ b/tests/transaction_test.go @@ -6,19 +6,11 @@ import ( func TestTransactions(t *testing.T) { notWorking := make(map[string]bool, 100) - // TODO: all commented out tests should work! + // TODO: all these tests should work! remove them from the array when they work snafus := []string{ - "EmptyTransaction", - "TransactionWithHihghNonce", - "TransactionWithRvalueWrongSize", - "TransactionWithSvalueHigh", - "TransactionWithSvalueTooHigh", - "TransactionWithSvalueWrongSize", - "ValuesAsDec", - "ValuesAsHex", - "libsecp256k1test", - "unpadedRValue", + "TransactionWithHihghNonce", // fails due to testing upper bound of 256 bit nonce + "TransactionWithSvalueHigh", // fails due to C++ wrong ECDSA r,s ranges. see https://github.com/ethereum/yellowpaper/pull/112 } for _, name := range snafus { @@ -42,3 +34,18 @@ func TestWrongRLPTransactions(t *testing.T) { t.Fatal(err) } } + +/* + +Not working until it's fields are in HEX + +func Test10MBtx(t *testing.T) { + notWorking := make(map[string]bool, 100) + var err error + err = RunTransactionTests("./files/TransactionTests/tt10mbDataField.json", + notWorking) + if err != nil { + t.Fatal(err) + } +} +*/ diff --git a/tests/transaction_test_util.go b/tests/transaction_test_util.go index 1b2ee88b1..567aba66f 100644 --- a/tests/transaction_test_util.go +++ b/tests/transaction_test_util.go @@ -90,9 +90,16 @@ func runTest(txTest TransactionTest) (err error) { if expectedV != uint64(tx.V) { return fmt.Errorf("V mismatch: %v %v", expectedV, uint64(tx.V)) } - if expectedTo != *tx.Recipient { - return fmt.Errorf("To mismatch: %v %v", expectedTo, *tx.Recipient) + if tx.Recipient == nil { + if expectedTo != common.BytesToAddress([]byte{}) { // "empty" or "zero" address + return fmt.Errorf("To mismatch when recipient is nil (contract creation): %v", expectedTo) + } + } else { + if expectedTo != *tx.Recipient { + return fmt.Errorf("To mismatch: %v %v", expectedTo, *tx.Recipient) + } } + if expectedValue.Cmp(tx.Amount) != 0 { return fmt.Errorf("Value mismatch: %v %v", expectedValue, tx.Amount) } @@ -120,14 +127,14 @@ func convertTestTypes(txTest TransactionTest) (sender, to common.Address, txInputData = mustConvertBytes(txTest.Transaction.Data) rlpBytes = mustConvertBytes(txTest.Rlp) - gasLimit = mustConvertBigInt10(txTest.Transaction.GasLimit) - gasPrice = mustConvertBigInt10(txTest.Transaction.GasPrice) - value = mustConvertBigInt10(txTest.Transaction.Value) + gasLimit = mustConvertBigInt(txTest.Transaction.GasLimit) + gasPrice = mustConvertBigInt(txTest.Transaction.GasPrice) + value = mustConvertBigInt(txTest.Transaction.Value) r = common.Bytes2Big(mustConvertBytes(txTest.Transaction.R)) s = common.Bytes2Big(mustConvertBytes(txTest.Transaction.S)) - nonce = mustConvertUintHex(txTest.Transaction.Nonce) + nonce = mustConvertUint(txTest.Transaction.Nonce) v = mustConvertUint(txTest.Transaction.V) return sender, to, txInputData, rlpBytes, gasLimit, gasPrice, value, r, s, nonce, v, nil |