Skip to content

Commit

Permalink
tests: adapt test by adding coins to realm
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Dec 23, 2024
1 parent a475671 commit 4fdaa01
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions gno/r/launchpad_grc20/sale_grc20_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func TestBuy(t *testing.T) {
notEnoughCoins := std.NewCoins(std.NewCoin("ugnot", 100*5))
tooManyCoins := std.NewCoins(std.NewCoin("ugnot", 100*11))
emptyCoins := std.NewCoins()
realmCoins := std.NewCoins(std.NewCoin("ugnot", 200*10))

tests := testBuyTestTable{
"Success": {
Expand Down Expand Up @@ -458,22 +459,19 @@ func TestBuy(t *testing.T) {
panic: true,
},
},
// FIXME: the realm does not seem to receive coins, see: https://github.com/gnolang/gno/issues/3381
/*
"Send too many coins": {
input: testBuyInput{
saleID: saleID,
amount: 10,
coins: tooManyCoins,
addr: alice,
proofs: nil,
},
expected: testBuyExpected{
panic: false,
balance: 10,
},
},
*/
"Send too many coins": {
input: testBuyInput{
saleID: saleID,
amount: 10,
coins: tooManyCoins,
addr: alice,
proofs: nil,
},
expected: testBuyExpected{
panic: false,
balance: 10,
},
},
}

for testName, test := range tests {
Expand All @@ -488,6 +486,7 @@ func TestBuy(t *testing.T) {

std.TestSetOrigCaller(test.input.addr)
std.TestSetOrigSend(test.input.coins, nil)
std.TestIssueCoins(std.CurrentRealm().Addr(), realmCoins)
Buy(test.input.saleID, test.input.amount, test.input.proofs)
sale := mustGetSale(test.input.saleID)
if !test.expected.panic {
Expand Down Expand Up @@ -538,6 +537,8 @@ func TestFinalize(t *testing.T) {
onGoingSaleID := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp, 100, 15, 10, 20, true)
onGoingSaleID2 := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp2, 100, 15, 10, 20, true)

realmCoins := std.NewCoins(std.NewCoin("ugnot", 200*10))

tests := testFinalizeTestTable{
"Success with 0 tokens sold": {
input: testFinalizeInput{
Expand Down Expand Up @@ -583,34 +584,29 @@ func TestFinalize(t *testing.T) {
panic: true,
},
},
// FIXME: the realm does not seem to have any coins to refund
/*
"Success with min goal not reached but some token sold": {
input: testFinalizeInput{
saleID: onGoingSaleID,
buyer: alice,
amount: 2,
skipHeights: 20, // 20 blocks passed ~= 100 seconds (close the onGoingEndTimestamp1)
},
expected: testFinalizeExpected{
panic: false,
},
},
*/
// FIXME: the realm has no coins
/*
"Success with min goal reached": {
input: testFinalizeInput{
saleID: onGoingSaleID2,
buyer: alice,
amount: 15,
skipHeights: 20, // 20 blocks passed ~= 100 seconds again (close the onGoingEndTimestamp2)
},
expected: testFinalizeExpected{
panic: false,
},
},
*/
"Success with min goal not reached but some token sold": {
input: testFinalizeInput{
saleID: onGoingSaleID,
buyer: alice,
amount: 2,
skipHeights: 20, // 20 blocks passed ~= 100 seconds (close the onGoingEndTimestamp1)
},
expected: testFinalizeExpected{
panic: false,
},
},

"Success with min goal reached": {
input: testFinalizeInput{
saleID: onGoingSaleID2,
buyer: alice,
amount: 15,
skipHeights: 20, // 20 blocks passed ~= 100 seconds again (close the onGoingEndTimestamp2)
},
expected: testFinalizeExpected{
panic: false,
},
},
}

banker := std.GetBanker(std.BankerTypeReadonly)
Expand All @@ -632,6 +628,7 @@ func TestFinalize(t *testing.T) {

coins := std.NewCoins(std.NewCoin("ugnot", int64(test.input.amount*sale.pricePerToken)))
std.TestSetOrigSend(coins, nil)
std.TestIssueCoins(std.CurrentRealm().Addr(), realmCoins)

if test.input.amount != 0 {
Buy(test.input.saleID, test.input.amount, nil)
Expand Down

0 comments on commit 4fdaa01

Please sign in to comment.