1) Fixed String method in Uint256 (#208)
2) Added ReverseString Method to Uint256
This commit is contained in:
parent
e12255dd73
commit
6f496754fb
12 changed files with 26 additions and 21 deletions
|
@ -46,13 +46,13 @@ func TestBlockDecodeEncode(t *testing.T) {
|
||||||
for _, tx := range b.Txs {
|
for _, tx := range b.Txs {
|
||||||
switch t := tx.(type) {
|
switch t := tx.(type) {
|
||||||
case *transaction.Contract:
|
case *transaction.Contract:
|
||||||
hashes = append(hashes, t.Hash.String())
|
hashes = append(hashes, t.Hash.ReverseString())
|
||||||
case *transaction.Miner:
|
case *transaction.Miner:
|
||||||
hashes = append(hashes, t.Hash.String())
|
hashes = append(hashes, t.Hash.ReverseString())
|
||||||
case *transaction.Claim:
|
case *transaction.Claim:
|
||||||
hashes = append(hashes, t.Hash.String())
|
hashes = append(hashes, t.Hash.ReverseString())
|
||||||
case *transaction.Invocation:
|
case *transaction.Invocation:
|
||||||
hashes = append(hashes, t.Hash.String())
|
hashes = append(hashes, t.Hash.ReverseString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func TestAddAndEncodeHeaders(t *testing.T) {
|
||||||
err := msgHeaders.Headers[0].createHash()
|
err := msgHeaders.Headers[0].createHash()
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
// Hash being correct, automatically verifies that the fields are encoded properly
|
// Hash being correct, automatically verifies that the fields are encoded properly
|
||||||
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", msgHeaders.Headers[0].Hash.String())
|
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", msgHeaders.Headers[0].Hash.ReverseString())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func TestEncodeDecode(t *testing.T) {
|
||||||
header := headerMsg.Headers[0]
|
header := headerMsg.Headers[0]
|
||||||
err = header.createHash()
|
err = header.createHash()
|
||||||
|
|
||||||
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", header.Hash.String())
|
assert.Equal(t, "f3c4ec44c07eccbda974f1ee34bc6654ab6d3f22cd89c2e5c593a16d6cc7e6e8", header.Hash.ReverseString())
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ func TestEncodeDecodeClaim(t *testing.T) {
|
||||||
assert.Equal(t, 1, int(len(c.Claims)))
|
assert.Equal(t, 1, int(len(c.Claims)))
|
||||||
|
|
||||||
claim := c.Claims[0]
|
claim := c.Claims[0]
|
||||||
assert.Equal(t, "497037a4c5e0a9ea1721e06f9d5e9aec183d11f2824ece93285729370f3a1baf", claim.PrevHash.String())
|
assert.Equal(t, "497037a4c5e0a9ea1721e06f9d5e9aec183d11f2824ece93285729370f3a1baf", claim.PrevHash.ReverseString())
|
||||||
assert.Equal(t, uint16(0), claim.PrevIndex)
|
assert.Equal(t, uint16(0), claim.PrevIndex)
|
||||||
assert.Equal(t, "abf142faf539c340e42722b5b34b505cf4fd73185fed775784e37c2c5ef1b866", c.Hash.String())
|
assert.Equal(t, "abf142faf539c340e42722b5b34b505cf4fd73185fed775784e37c2c5ef1b866", c.Hash.ReverseString())
|
||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
|
@ -27,12 +27,12 @@ func TestEncodeDecodeContract(t *testing.T) {
|
||||||
|
|
||||||
input := c.Inputs[0]
|
input := c.Inputs[0]
|
||||||
|
|
||||||
assert.Equal(t, "eec17cc828d6ede932b57e4eaf79c2591151096a7825435cd67f498f9fa98d88", input.PrevHash.String())
|
assert.Equal(t, "eec17cc828d6ede932b57e4eaf79c2591151096a7825435cd67f498f9fa98d88", input.PrevHash.ReverseString())
|
||||||
assert.Equal(t, 0, int(input.PrevIndex))
|
assert.Equal(t, 0, int(input.PrevIndex))
|
||||||
assert.Equal(t, int64(70600000000), c.Outputs[0].Amount)
|
assert.Equal(t, int64(70600000000), c.Outputs[0].Amount)
|
||||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", c.Outputs[0].AssetID.String())
|
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", c.Outputs[0].AssetID.ReverseString())
|
||||||
assert.Equal(t, "a8666b4830229d6a1a9b80f6088059191c122d2b", c.Outputs[0].ScriptHash.String())
|
assert.Equal(t, "a8666b4830229d6a1a9b80f6088059191c122d2b", c.Outputs[0].ScriptHash.String())
|
||||||
assert.Equal(t, "bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79", c.Hash.String())
|
assert.Equal(t, "bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79", c.Hash.ReverseString())
|
||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
|
@ -26,5 +26,5 @@ func TestEncodeDecodeEnrollment(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
||||||
assert.Equal(t, "988832f693785dcbcb8d5a0e9d5d22002adcbfb1eb6bbeebf8c494fff580e147", enroll.Hash.String())
|
assert.Equal(t, "988832f693785dcbcb8d5a0e9d5d22002adcbfb1eb6bbeebf8c494fff580e147", enroll.Hash.ReverseString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestEncodeDecodeInvoc(t *testing.T) {
|
||||||
assert.Equal(t, "31363a30373a3032203a2030333366616431392d643638322d343035382d626437662d313563393331323434336538", hex.EncodeToString(attr2.Data))
|
assert.Equal(t, "31363a30373a3032203a2030333366616431392d643638322d343035382d626437662d313563393331323434336538", hex.EncodeToString(attr2.Data))
|
||||||
|
|
||||||
assert.Equal(t, "050034e23004141ad842821c7341d5a32b17d7177a1750d30014ca14628c9e5bc6a9346ca6bcdf050ceabdeb2bdc774953c1087472616e736665726703e1df72015bdef1a1b9567d4700635f23b1f406f1", hex.EncodeToString(i.Script))
|
assert.Equal(t, "050034e23004141ad842821c7341d5a32b17d7177a1750d30014ca14628c9e5bc6a9346ca6bcdf050ceabdeb2bdc774953c1087472616e736665726703e1df72015bdef1a1b9567d4700635f23b1f406f1", hex.EncodeToString(i.Script))
|
||||||
assert.Equal(t, "b2a22cd9dd7636ae23e25576866cd1d9e2f3d85a85e80874441f085cd60006d1", i.Hash.String())
|
assert.Equal(t, "b2a22cd9dd7636ae23e25576866cd1d9e2f3d85a85e80874441f085cd60006d1", i.Hash.ReverseString())
|
||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestEncodeDecodeMiner(t *testing.T) {
|
||||||
assert.Equal(t, types.Miner, m.Type)
|
assert.Equal(t, types.Miner, m.Type)
|
||||||
assert.Equal(t, uint32(571397116), m.Nonce)
|
assert.Equal(t, uint32(571397116), m.Nonce)
|
||||||
|
|
||||||
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", m.Hash.String())
|
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", m.Hash.ReverseString())
|
||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
|
@ -28,6 +28,6 @@ func TestEncodeDecodePublish(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
||||||
assert.Equal(t, "5467a1fc8723ceffa8e5ee59399b02eea1df6fbaa53768c6704b90b960d223fa", publ.Hash.String())
|
assert.Equal(t, "5467a1fc8723ceffa8e5ee59399b02eea1df6fbaa53768c6704b90b960d223fa", publ.Hash.ReverseString())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestEncodeDecodeRegister(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
||||||
assert.Equal(t, "0c092117b4ba47b81001712425e6e7f760a637695eaf23741ba335925b195ecd", reg.Hash.String())
|
assert.Equal(t, "0c092117b4ba47b81001712425e6e7f760a637695eaf23741ba335925b195ecd", reg.Hash.ReverseString())
|
||||||
}
|
}
|
||||||
func TestEncodeDecodeGenesisRegister(t *testing.T) {
|
func TestEncodeDecodeGenesisRegister(t *testing.T) {
|
||||||
|
|
||||||
|
@ -50,5 +50,5 @@ func TestEncodeDecodeGenesisRegister(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
assert.Equal(t, rawtx, hex.EncodeToString(buf.Bytes()))
|
||||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", reg.Hash.String())
|
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", reg.Hash.ReverseString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestEncodeDecodeState(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, 1, len(s.Inputs))
|
assert.Equal(t, 1, len(s.Inputs))
|
||||||
input := s.Inputs[0]
|
input := s.Inputs[0]
|
||||||
assert.Equal(t, "a192cbabc6d613ecfcce43fd09e9197556ca5cf7d4bd1f6c65726ea9f08441cb", input.PrevHash.String())
|
assert.Equal(t, "a192cbabc6d613ecfcce43fd09e9197556ca5cf7d4bd1f6c65726ea9f08441cb", input.PrevHash.ReverseString())
|
||||||
assert.Equal(t, uint16(0), input.PrevIndex)
|
assert.Equal(t, uint16(0), input.PrevIndex)
|
||||||
|
|
||||||
assert.Equal(t, 1, len(s.Descriptors))
|
assert.Equal(t, 1, len(s.Descriptors))
|
||||||
|
@ -43,5 +43,5 @@ func TestEncodeDecodeState(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, rawtxBytes, buf.Bytes())
|
assert.Equal(t, rawtxBytes, buf.Bytes())
|
||||||
assert.Equal(t, "8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724", s.Hash.String())
|
assert.Equal(t, "8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724", s.Hash.ReverseString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,11 @@ func (u Uint256) Equals(other Uint256) bool {
|
||||||
|
|
||||||
// String implements the stringer interface.
|
// String implements the stringer interface.
|
||||||
func (u Uint256) String() string {
|
func (u Uint256) String() string {
|
||||||
|
return hex.EncodeToString(u.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReverseString displays a reverse string representation of Uint256.
|
||||||
|
func (u Uint256) ReverseString() string {
|
||||||
return hex.EncodeToString(slice.Reverse(u.Bytes()))
|
return hex.EncodeToString(slice.Reverse(u.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestUint256DecodeString(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, hexStr, val.Reverse().String())
|
assert.Equal(t, hexStr, val.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUint256DecodeBytes(t *testing.T) {
|
func TestUint256DecodeBytes(t *testing.T) {
|
||||||
|
@ -26,7 +26,7 @@ func TestUint256DecodeBytes(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, hexStr, val.Reverse().String())
|
assert.Equal(t, hexStr, val.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUInt256Equals(t *testing.T) {
|
func TestUInt256Equals(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue