Skip to content

Commit

Permalink
Still fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Villaquiranm committed Dec 19, 2024
1 parent cd39189 commit 675b56f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
23 changes: 21 additions & 2 deletions gnovm/stdlibs/std/crypto.gno
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ func EncodeBech32(prefix string, bz [20]byte) Address {
}

func DecodeBech32(addr Address) (string, [20]byte, bool) {
prefix, bz, err := bech32.Decode(string(addr))
prefix, bz, err := decodeAndConvert(string(addr))
if err != nil || len(bz) != 20 {
return "", [20]byte{}, false
}
return prefix, [20]byte(bz), true
/* For some reason [20]byte(bz) fails with: 'cannot convert []uint8 to ArrayKind'
Maybe there is an issue to create
*/
result := [20]byte{}
for index,b:= range bz{
result[index]=b
}
return prefix, result, true
}

func convertAndEncode(hrp string, data []byte) (string, error) {
Expand All @@ -44,3 +51,15 @@ func convertAndEncode(hrp string, data []byte) (string, error) {
}
return bech32.Encode(hrp, converted)
}

func decodeAndConvert(bech string) (string, []byte, error) {
hrp, data, err := bech32.Decode(bech)
if err != nil {
return "", nil, errors.New("decoding bech32 failed"+err.Error())
}
converted, err := bech32.ConvertBits(data, 5, 8, false)
if err != nil {
return "", nil, errors.New("decoding bech32 failed"+err.Error())
}
return hrp, converted, nil
}
2 changes: 1 addition & 1 deletion gnovm/tests/files/std5.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {

// Stacktrace:
// panic: frame not found
// callerAt<VPBlock(3,48)>(n<VPBlock(1,0)>)
// callerAt<VPBlock(3,49)>(n<VPBlock(1,0)>)
// gonative:std.callerAt
// std<VPBlock(2,0)>.GetCallerAt(2)
// std/native.gno:45
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/std8.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {

// Stacktrace:
// panic: frame not found
// callerAt<VPBlock(3,48)>(n<VPBlock(1,0)>)
// callerAt<VPBlock(3,49)>(n<VPBlock(1,0)>)
// gonative:std.callerAt
// std<VPBlock(2,0)>.GetCallerAt(4)
// std/native.gno:45
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_natbind0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
// "Closure": {
// "@type": "/gno.RefValue",
// "Escaped": true,
// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:9"
// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:10"
// },
// "FileName": "native.gno",
// "IsMethod": false,
Expand Down

0 comments on commit 675b56f

Please sign in to comment.