Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getting SchemaHash from int for short ints #462

Merged
merged 1 commit into from
Apr 18, 2024
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))
})
}
}
Loading