-
Notifications
You must be signed in to change notification settings - Fork 375
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
feat(examples): added check for overflow/underflow #2874
base: master
Are you sure you want to change the base?
Changes from all commits
1e6e2ac
97b213c
295ab0d
8fa25ef
7e174be
0356eca
1d6f6e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ var ( | |
ErrInsufficientAllowance = errors.New("insufficient allowance") | ||
ErrInvalidAddress = errors.New("invalid address") | ||
ErrCannotTransferToSelf = errors.New("cannot send transfer to self") | ||
ErrUnderflow = errors.New("the amount is higher than the total supply") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to be used somewhere? It should be deleted if not. |
||
) | ||
|
||
type Token interface { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
banker "gno.land/p/demo/grc/grc20" | ||
"gno.land/p/demo/testutils" | ||
) | ||
|
||
const uint64_max = 1<<64 - 1 | ||
|
||
func main() { | ||
b := banker.NewBanker("Dummy", "DUMMY", 6) | ||
var owner = testutils.TestAddress("owner") | ||
// Mint uint64_max - 1000 tokens for owner | ||
b.Mint(owner, uint64_max-1000) | ||
// Try to mint 1001 tokens for owner, should fail because it exceeds the limit | ||
println(b.Mint(owner, 1001).Error()) | ||
|
||
} | ||
|
||
// Output: | ||
// you can't mint more than 1000 tokens | ||
Comment on lines
+1
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, filetests should be discouraged. We should strive to write proper tests, that are more Go idiomatic. Please write a unit test for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lines can be shortened using
ufmt.Errorf
.