-
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.
- Loading branch information
Showing
5 changed files
with
145 additions
and
218 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
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,70 @@ | ||
package gns | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
|
||
"gno.land/p/demo/testutils" | ||
"gno.land/p/demo/uassert" | ||
|
||
"gno.land/r/gnoswap/v1/consts" | ||
|
||
"gno.land/r/gnoswap/v1/gns" | ||
) | ||
|
||
const ( | ||
GNO_VM_DEFAULT_HEIGHT = int64(123) | ||
) | ||
|
||
var ( | ||
addr01 = testutils.TestAddress("addr01") | ||
addr01Realm = std.NewUserRealm(addr01) | ||
emissionRealm = std.NewCodeRealm(consts.EMISSION_PATH) | ||
) | ||
|
||
func TestInitData(t *testing.T) { | ||
t.Run("total supply", func(t *testing.T) { | ||
uassert.Equal(t, INITIAL_MINT_AMOUNT, TotalSupply()) | ||
}) | ||
|
||
t.Run("balance of admin", func(t *testing.T) { | ||
uassert.Equal(t, INITIAL_MINT_AMOUNT, BalanceOf(a2u(consts.ADMIN))) | ||
}) | ||
|
||
t.Run("last minted height", func(t *testing.T) { | ||
uassert.Equal(t, GNO_VM_DEFAULT_HEIGHT, lastMintedHeight) // gnoVM(in test) default height | ||
}) | ||
} | ||
|
||
func TestMint(t *testing.T) { | ||
t.Run("panic if caller is not emission", func(t *testing.T) { | ||
std.TestSetRealm(addr01Realm) | ||
uassert.PanicsWithMessage(t, | ||
`caller(g1v9jxgu3sx9047h6lta047h6lta047h6l0js7st) has no permission`, | ||
func() { Mint(a2u(addr01)) }) | ||
}) | ||
|
||
t.Run("success mint", func(t *testing.T) { | ||
std.TestSkipHeights(1) | ||
|
||
uassert.Equal(t, uint64(0), gns.BalanceOf(a2u(consts.EMISSION_ADDR))) | ||
|
||
std.TestSetRealm(emissionRealm) | ||
uassert.Equal(t, amountPerBlockPerHalvingYear[1], Mint(a2u(consts.EMISSION_ADDR))) // 1 block for year 01 | ||
|
||
uassert.Equal(t, std.GetHeight(), GetLastMintedHeight()) | ||
uassert.Equal(t, MAX_EMISSION_AMOUNT-amountPerBlockPerHalvingYear[1], GetLeftEmissionAmount()) | ||
|
||
uassert.Equal(t, amountPerBlockPerHalvingYear[1], gns.BalanceOf(a2u(consts.EMISSION_ADDR))) | ||
}) | ||
} | ||
|
||
func TestSkipIfSameHeight(t *testing.T) { | ||
t.Run("should skip if height is same", func(t *testing.T) { | ||
uassert.True(t, skipIfSameHeight(1, 1)) | ||
}) | ||
|
||
t.Run("should not skip if height is different", func(t *testing.T) { | ||
uassert.False(t, skipIfSameHeight(1, 2)) | ||
}) | ||
} |
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.