PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/onbloc/uint256/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
onbloc / uint256
Files
17 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/onbloc/uint256/v0
gno
0.9

Files (17)

  • README.mdmarkdown
  • gnomod.tomltoml
  • arithmetic.gnogno
  • bits_table.gnogno
  • bitwise.gnogno
  • cmp.gnogno
  • conversion.gnogno
  • error.gnogno
  • mod.gnogno
  • uint256.gnogno
  • utils.gnogno
  • arithmetic_test.gnogno
  • bitwise_test.gnogno
  • cmp_test.gnogno
  • conversion_test.gnogno
  • uint256_test.gnogno
  • LICENSEother
  • conversion_test.gnogno
    1package uint25623import "testing"45func TestIsUint64(t *testing.T) {6	tests := []struct {7		x    string8

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.

    want bool
    9 }{
    10 {"0x0", true},
    11 {"0x1", true},
    12 {"0x10", true},
    13 {"0xffffffffffffffff", true},
    14 {"0x10000000000000000", false},
    15 }
    16
    17 for _, tt := range tests {
    18 x := MustFromHex(tt.x)
    19 got := x.IsUint64()
    20
    21 if got != tt.want {
    22 t.Errorf("IsUint64(%s) = %v, want %v", tt.x, got, tt.want)
    23 }
    24 }
    25}
    26
    27func TestDec(t *testing.T) {
    28 tests := []struct {
    29 name string
    30 z Uint
    31 want string
    32 }{
    33 {
    34 name: "zero",
    35 z: Uint{arr: [4]uint64{0, 0, 0, 0}},
    36 want: "0",
    37 },
    38 {
    39 name: "less than 20 digits",
    40 z: Uint{arr: [4]uint64{1234567890, 0, 0, 0}},
    41 want: "1234567890",
    42 },
    43 {
    44 name: "max possible value",
    45 z: Uint{arr: [4]uint64{^uint64(0), ^uint64(0), ^uint64(0), ^uint64(0)}},
    46 want: twoPow256Sub1,
    47 },
    48 }
    49
    50 for _, tt := range tests {
    51 t.Run(tt.name, func(t *testing.T) {
    52 result := tt.z.Dec()
    53 if result != tt.want {
    54 t.Errorf("Dec(%v) = %s, want %s", tt.z, result, tt.want)
    55 }
    56 })
    57 }
    58}
    59
    60func TestUint_Scan(t *testing.T) {
    61 tests := []struct {
    62 name string
    63 input any
    64 want *Uint
    65 wantErr bool
    66 }{
    67 {
    68 name: "nil",
    69 input: nil,
    70 want: NewUint(0),
    71 },
    72 {
    73 name: "valid scientific notation",
    74 input: "1e4",
    75 want: NewUint(10000),
    76 },
    77 {
    78 name: "valid decimal string",
    79 input: "12345",
    80 want: NewUint(12345),
    81 },
    82 {
    83 name: "valid byte slice",
    84 input: []byte("12345"),
    85 want: NewUint(12345),
    86 },
    87 {
    88 name: "invalid string",
    89 input: "invalid",
    90 wantErr: true,
    91 },
    92 {
    93 name: "out of range",
    94 input: "115792089237316195423570985008687907853269984665640564039457584007913129639936", // 2^256
    95 wantErr: true,
    96 },
    97 {
    98 name: "unsupported type",
    99 input: 123,
    100 wantErr: true,
    101 },
    102 }
    103
    104 for _, tt := range tests {
    105 t.Run(tt.name, func(t *testing.T) {
    106 z := new(Uint)
    107 err := z.Scan(tt.input)
    108
    109 if tt.wantErr {
    110 if err == nil {
    111 t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr)
    112 }
    113 } else {
    114 if err != nil {
    115 t.Errorf("Scan() error = %v, wantErr %v", err, tt.wantErr)
    116 }
    117 if !z.Eq(tt.want) {
    118 t.Errorf("Scan() = %v, want %v", z, tt.want)
    119 }
    120 }
    121 })
    122 }
    123}
    124
    125func TestSetBytes(t *testing.T) {
    126 tests := []struct {
    127 input []byte
    128 expected string
    129 }{
    130 {[]byte{}, "0"},
    131 {[]byte{0x01}, "1"},
    132 {[]byte{0x12, 0x34}, "4660"},
    133 {[]byte{0x12, 0x34, 0x56}, "1193046"},
    134 {[]byte{0x12, 0x34, 0x56, 0x78}, "305419896"},
    135 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a}, "78187493530"},
    136 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}, "20015998343868"},
    137 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde}, "5124095576030430"},
    138 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}, "1311768467463790320"},
    139 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12}, "335812727670730321938"},
    140 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34}, "85968058283706962416180"},
    141 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56}, "22007822920628982378542166"},
    142 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78}, "5634002667681019488906794616"},
    143 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a}, "1442304682926340989160139421850"},
    144 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}, "369229998829143293224995691993788"},
    145 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde}, "94522879700260683065598897150409950"},
    146 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}, "24197857203266734864793317670504947440"},
    147 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12}, "6194651444036284125387089323649266544658"},
    148 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34}, "1585830769673288736099094866854212235432500"},
    149 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56}, "405972677036361916441368285914678332270720086"},
    150 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78}, "103929005321308650608990281194157653061304342136"},
    151 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a}, "26605825362255014555901511985704359183693911586970"},
    152 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}, "6811091292737283726310787068340315951025641366264508"},
    153 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde}, "1743639370940744633935561489495120883462564189763714270"},
    154 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}, "446371678960830626287503741310750946166416432579510853360"},
    155 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12}, "114271149813972640329600957775552242218602606740354778460178"},
    156 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34}, "29253414352376995924377845190541374007962267325530823285805620"},
    157 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56}, "7488874074208510956640728368778591746038340435335890761166238806"},
    158 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78}, "1917151762997378804900026462407319486985815151445988034858557134456"},
    159 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a}, "490790851327328974054406774376273788668368678770172936923790626420890"},
    160 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}, "125642457939796217357928134240326089899102381765164271852490400363748028"},
    161 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde}, "32164469232587831643629602365523479014170209731882053594237542493119495390"},
    162 {[]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}, "8234104123542484900769178205574010627627573691361805720124810878238590820080"},
    163 // over 32 bytes (last 32 bytes are used)
    164 {append([]byte{0xff}, []byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}...), "8234104123542484900769178205574010627627573691361805720124810878238590820080"},
    165 }
    166
    167 for _, test := range tests {
    168 z := new(Uint)
    169 z.SetBytes(test.input)
    170 expected := MustFromDecimal(test.expected)
    171 if z.Cmp(expected) != 0 {
    172 t.Errorf("SetBytes(%x) = %s, expected %s", test.input, z.String(), test.expected)
    173 }
    174 }
    175}
    176