From c617a6ec790a974770f3553fe0b2fed9ad560fcc Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Wed, 15 Apr 2015 22:37:16 +0200 Subject: Fixes for TransactionTests * Include tests which now has consistent HEX encodings * Comment out two failing tests: " "TransactionWithHihghNonce" due to wrong nonce size "TransactionWithSvalueHigh" due to wrong ECDSA s range * Cleanup conversion functions and fix expected encodings for tests validation fields --- tests/blocktest.go | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'tests/blocktest.go') 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 +} -- cgit v1.2.3