Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func NewSchemaHashFromHex(s string) (SchemaHash, error) {
func NewSchemaHashFromInt(i *big.Int) SchemaHash {
var sh SchemaHash
b := intToBytes(i)
copy(sh[len(sh)-len(b):], b)
copy(sh[:], b)

return sh
}
Expand Down
34 changes: 34 additions & 0 deletions claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,37 @@ func TestNewClaimFromBigInts(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "2qNkLwz97jdzZBkdJYwVdXyGARGfVSGLJxELVC9ceH", userID.String())
}

func TestNewSchemaHashFromInt(t *testing.T) {
testCases := []struct {
title string
input string
want string
}{
{
title: "very long int",
input: "3044275373607097841737703342662468617701234",
want: "109319132382347594354104577870198015858",
},
{
title: "16-bytes int",
input: "304427537360709784173770334266246861770",
want: "304427537360709784173770334266246861770",
},
{
title: "15-bytes int",
input: "1161257907061317498916776531476452695",
want: "1161257907061317498916776531476452695",
},
}

for i := range testCases {
tc := testCases[i]
t.Run(tc.title, func(t *testing.T) {
bi, ok := new(big.Int).SetString(tc.input, 10)
require.True(t, ok)
sc := NewSchemaHashFromInt(bi)
require.Equal(t, tc.want, bytesToInt(sc[:]).Text(10))
})
}
}