-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rror GSW-719 fix: tick rouding error
- Loading branch information
Showing
6 changed files
with
1,598 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package swap_scneraio | ||
|
||
import ( | ||
"std" | ||
"strconv" | ||
"testing" | ||
|
||
"gno.land/p/demo/grc/grc20" | ||
"gno.land/p/demo/grc/grc721" | ||
|
||
"gno.land/r/demo/users" | ||
|
||
"gno.land/r/demo/wugnot" | ||
) | ||
|
||
func balanceOf(token *grc20.AdminToken, addr std.Address) uint64 { | ||
balance, err := token.BalanceOf(addr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return balance | ||
} | ||
|
||
func a2u(addr std.Address) users.AddressOrName { | ||
return users.AddressOrName(addr) | ||
} | ||
|
||
func tid(tokenId interface{}) grc721.TokenID { | ||
if tokenId == nil { | ||
panic("tid() || tokenId is nil") | ||
} | ||
|
||
switch tokenId.(type) { | ||
case bigint: | ||
return grc721.TokenID(string(tokenId.(bigint))) | ||
case string: | ||
return grc721.TokenID(tokenId.(string)) | ||
case int: | ||
return grc721.TokenID(strconv.Itoa(tokenId.(int))) | ||
case uint64: | ||
return grc721.TokenID(strconv.Itoa(int(tokenId.(uint64)))) | ||
case grc721.TokenID: | ||
return tokenId.(grc721.TokenID) | ||
default: | ||
panic("[STAKER] utils.gno__tid() || unsupported tokenId type") | ||
} | ||
} | ||
|
||
func ugnotBalanceOf(addr std.Address) uint64 { | ||
testBanker := std.GetBanker(std.BankerTypeRealmIssue) | ||
|
||
coins := testBanker.GetCoins(addr) | ||
if len(coins) == 0 { | ||
return 0 | ||
} | ||
|
||
return uint64(testBanker.GetCoins(addr)[0].Amount) | ||
} | ||
|
||
func wugnotBalanceOf(addr std.Address) uint64 { | ||
return wugnot.BalanceOf(a2u(addr)) | ||
} | ||
|
||
/* HELPER */ | ||
func shouldEQ(t *testing.T, got, expected interface{}) { | ||
if got != expected { | ||
t.Errorf("got %v, expected %v", got, expected) | ||
} | ||
} | ||
|
||
func shouldNEQ(t *testing.T, got, expected interface{}) { | ||
if got == expected { | ||
t.Errorf("got %v, didn't expected %v", got, expected) | ||
} | ||
} | ||
|
||
func shouldGT(t *testing.T, l, r interface{}) { | ||
if !(l < r) { | ||
t.Errorf("expected %v < %v", l, r) | ||
} | ||
} | ||
|
||
func shouldLT(t *testing.T, l, r interface{}) { | ||
if !(l > r) { | ||
t.Errorf("expected %v > %v", l, r) | ||
} | ||
} | ||
|
||
func shouldPanic(t *testing.T, f func()) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Errorf("expected panic") | ||
} | ||
}() | ||
f() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.