aboutsummaryrefslogtreecommitdiffstats
path: root/tests/blocktest.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-04-16 04:37:16 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-04-16 04:37:16 +0800
commitc617a6ec790a974770f3553fe0b2fed9ad560fcc (patch)
tree916080981cc2dc8c32ec57fb8fc4f18ac801256a /tests/blocktest.go
parent2d8a2d0c9997e658bbdbf7a172c920dbb3c47821 (diff)
downloaddexon-c617a6ec790a974770f3553fe0b2fed9ad560fcc.tar.gz
dexon-c617a6ec790a974770f3553fe0b2fed9ad560fcc.tar.zst
dexon-c617a6ec790a974770f3553fe0b2fed9ad560fcc.zip
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
Diffstat (limited to 'tests/blocktest.go')
-rw-r--r--tests/blocktest.go46
1 files changed, 22 insertions, 24 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
+}