-
Notifications
You must be signed in to change notification settings - Fork 1
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
GSW-1144 feat: emission contract that calls gns mint #248
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package emission | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
|
||
pusers "gno.land/p/demo/users" | ||
|
||
"gno.land/r/demo/gns" | ||
) | ||
|
||
func TestEmitGns(t *testing.T) { | ||
shouldEQ(t, gns.TotalSupply(), 100000000000000) // GSA has | ||
shouldEQ(t, gnsBalance(emissionAddr), 0) | ||
|
||
EmitGns() // 1 ~ 123 height | ||
|
||
shouldEQ(t, gnsBalance(emissionAddr), 4387842345) | ||
shouldEQ(t, gns.TotalSupply(), 100000000000000+4387842345) | ||
|
||
shouldEQ(t, std.GetHeight(), 123) | ||
} | ||
|
||
func TestEmitGnsSameBlock(t *testing.T) { | ||
// request mint again in same block => do not mint again | ||
// it may happen because single block can have multiple txs & msgs | ||
EmitGns() | ||
shouldEQ(t, gns.TotalSupply(), 100000000000000+4387842345) | ||
} | ||
|
||
func TestEmitGnsAllAmount(t *testing.T) { | ||
std.TestSkipHeights(75686400 - 1) | ||
gns.TestSetLastMintedHeight(std.GetHeight()) | ||
std.TestSkipHeights(1) | ||
|
||
EmitGns() | ||
shouldEQ(t, gns.TotalSupply(), 100000000000000+4387842345+2229594) | ||
// all emission duratino has been passed | ||
|
||
std.TestSkipHeights(1) | ||
EmitGns() // since all emission has been done, no more minting | ||
shouldEQ(t, gns.TotalSupply(), 100000000000000+4387842345+2229594) | ||
} | ||
|
||
// UTILs | ||
func gnsBalance(addr std.Address) uint64 { | ||
a2u := pusers.AddressOrName(addr) | ||
|
||
return gns.BalanceOf(a2u) | ||
} | ||
|
||
func shouldEQ(t *testing.T, got, expected interface{}) { | ||
if got != expected { | ||
t.Errorf("got %v, expected %v", got, expected) | ||
} | ||
} | ||
|
||
func shouldPanicWithMsg(t *testing.T, f func(), msg string) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Errorf("The code did not panic") | ||
} else { | ||
if r != msg { | ||
t.Errorf("excepted panic(%v), got(%v)", msg, r) | ||
} | ||
} | ||
}() | ||
f() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package emission | ||
|
||
import ( | ||
"std" | ||
|
||
pusers "gno.land/p/demo/users" | ||
"gno.land/r/demo/gnoswap/consts" | ||
"gno.land/r/demo/gns" | ||
) | ||
|
||
var emissionAddr std.Address = consts.EMISSION_ADDR | ||
|
||
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. // EmitGns mints new GNS tokens to the emission address. 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. |
||
func EmitGns() { | ||
gns.Mint(a2u(emissionAddr)) | ||
} | ||
|
||
func a2u(addr std.Address) pusers.AddressOrName { | ||
return pusers.AddressOrName(addr) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,12 @@ func Mint(address pusers.AddressOrName) { | |
// println("height:", i, "minted:", amount) | ||
} | ||
} | ||
|
||
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. XXX: Remove this 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. |
||
// ONLY FOR EMISSION TESTING, REMOVE THIS FUNCTION IN PRODUCTION | ||
func TestSetLastMintedHeight(height int64) { | ||
caller := std.PrevRealm().Addr() | ||
if caller != consts.EMISSION_ADDR { | ||
panic("only emission contract can call TestSetLastMintedHeight") | ||
} | ||
lastMintedHeight = height | ||
} |
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.
// emissionAddr is the address from which GNS tokens will be emitted.
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.
92eedc4