diff --git a/types/Uint.go b/types/Uint.go index 4ba409e..2068e30 100644 --- a/types/Uint.go +++ b/types/Uint.go @@ -202,7 +202,9 @@ type U256 struct { } func (u *U256) Process() { - u.Value = utiles.AddHex(utiles.BytesToHex(u.NextBytes(32))) + reverseData := u.NextBytes(32) + Reverse(reverseData) + u.Value = decimal.NewFromBigInt(utiles.U256(utiles.BytesToHex(reverseData)), 0) } func (u *U256) Encode(value interface{}) string { diff --git a/types/types_test.go b/types/types_test.go index 4dee48d..e56569a 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -368,6 +368,8 @@ func TestU256(t *testing.T) { raw := "0x1001000000000000000000000000000000000000000000000000000000000000" m := ScaleDecoder{} m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes(raw)}, nil) - assert.Equal(t, raw, utiles.AddHex(Encode("U256", utiles.U256DecoderToBigInt(m.ProcessAndUpdateData("U256").(string))))) + assert.Equal(t, raw, utiles.AddHex(Encode("U256", m.ProcessAndUpdateData("U256").(decimal.Decimal)))) assert.Equal(t, raw, utiles.AddHex(Encode("U256", "0x1001000000000000000000000000000000000000000000000000000000000000"))) + m.Init(scaleBytes.ScaleBytes{Data: utiles.HexToBytes("0x00b5070000000000000000000000000000000000000000000000000000000000")}, nil) + assert.Equal(t, int64(505088), m.ProcessAndUpdateData("U256").(decimal.Decimal).IntPart()) }