TestScriptNumBytes ensures that converting from integral script numbers to byte representations works as expected.
(t *testing.T)
| 25 | // TestScriptNumBytes ensures that converting from integral script numbers to |
| 26 | // byte representations works as expected. |
| 27 | func TestScriptNumBytes(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | tests := []struct { |
| 31 | num scriptNum |
| 32 | serialized []byte |
| 33 | }{ |
| 34 | {0, nil}, |
| 35 | {1, hexToBytes("01")}, |
| 36 | {-1, hexToBytes("81")}, |
| 37 | {127, hexToBytes("7f")}, |
| 38 | {-127, hexToBytes("ff")}, |
| 39 | {128, hexToBytes("8000")}, |
| 40 | {-128, hexToBytes("8080")}, |
| 41 | {129, hexToBytes("8100")}, |
| 42 | {-129, hexToBytes("8180")}, |
| 43 | {256, hexToBytes("0001")}, |
| 44 | {-256, hexToBytes("0081")}, |
| 45 | {32767, hexToBytes("ff7f")}, |
| 46 | {-32767, hexToBytes("ffff")}, |
| 47 | {32768, hexToBytes("008000")}, |
| 48 | {-32768, hexToBytes("008080")}, |
| 49 | {65535, hexToBytes("ffff00")}, |
| 50 | {-65535, hexToBytes("ffff80")}, |
| 51 | {524288, hexToBytes("000008")}, |
| 52 | {-524288, hexToBytes("000088")}, |
| 53 | {7340032, hexToBytes("000070")}, |
| 54 | {-7340032, hexToBytes("0000f0")}, |
| 55 | {8388608, hexToBytes("00008000")}, |
| 56 | {-8388608, hexToBytes("00008080")}, |
| 57 | {2147483647, hexToBytes("ffffff7f")}, |
| 58 | {-2147483647, hexToBytes("ffffffff")}, |
| 59 | |
| 60 | // Values that are out of range for data that is interpreted as |
| 61 | // numbers, but are allowed as the result of numeric operations. |
| 62 | {2147483648, hexToBytes("0000008000")}, |
| 63 | {-2147483648, hexToBytes("0000008080")}, |
| 64 | {2415919104, hexToBytes("0000009000")}, |
| 65 | {-2415919104, hexToBytes("0000009080")}, |
| 66 | {4294967295, hexToBytes("ffffffff00")}, |
| 67 | {-4294967295, hexToBytes("ffffffff80")}, |
| 68 | {4294967296, hexToBytes("0000000001")}, |
| 69 | {-4294967296, hexToBytes("0000000081")}, |
| 70 | {281474976710655, hexToBytes("ffffffffffff00")}, |
| 71 | {-281474976710655, hexToBytes("ffffffffffff80")}, |
| 72 | {72057594037927935, hexToBytes("ffffffffffffff00")}, |
| 73 | {-72057594037927935, hexToBytes("ffffffffffffff80")}, |
| 74 | {9223372036854775807, hexToBytes("ffffffffffffff7f")}, |
| 75 | {-9223372036854775807, hexToBytes("ffffffffffffffff")}, |
| 76 | } |
| 77 | |
| 78 | for _, test := range tests { |
| 79 | gotBytes := test.num.Bytes() |
| 80 | if !bytes.Equal(gotBytes, test.serialized) { |
| 81 | t.Errorf("Bytes: did not get expected bytes for %d - "+ |
| 82 | "got %x, want %x", test.num, gotBytes, |
| 83 | test.serialized) |
| 84 | continue |
nothing calls this directly
no test coverage detected
searching dependent graphs…