From 4fdaa011881dde8582706853b28762744f647d26 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 23 Dec 2024 12:21:14 +0100 Subject: [PATCH 1/2] tests: adapt test by adding coins to realm --- gno/r/launchpad_grc20/sale_grc20_test.gno | 85 +++++++++++------------ 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/gno/r/launchpad_grc20/sale_grc20_test.gno b/gno/r/launchpad_grc20/sale_grc20_test.gno index 7aaa49b48..32792da0a 100644 --- a/gno/r/launchpad_grc20/sale_grc20_test.gno +++ b/gno/r/launchpad_grc20/sale_grc20_test.gno @@ -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": { @@ -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 { @@ -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 { @@ -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{ @@ -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) @@ -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) From 889b0b1f2b0c3dc00efedd108be5172922d478e2 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 30 Dec 2024 10:29:50 +0100 Subject: [PATCH 2/2] fix: adapt test --- gno/r/launchpad_grc20/sale_grc20_test.gno | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gno/r/launchpad_grc20/sale_grc20_test.gno b/gno/r/launchpad_grc20/sale_grc20_test.gno index cb751858a..32792da0a 100644 --- a/gno/r/launchpad_grc20/sale_grc20_test.gno +++ b/gno/r/launchpad_grc20/sale_grc20_test.gno @@ -331,6 +331,7 @@ func TestBuy(t *testing.T) { badCoin := std.NewCoins(std.NewCoin("notugnot", 100*10)) manyCoins := std.NewCoins(std.NewCoin("ugnot", 100*10), std.NewCoin("notugnot", 100*10)) 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)) @@ -534,7 +535,7 @@ func TestFinalize(t *testing.T) { NewToken("TestFinalizeToken", "TestFinalizeToken", "image", 18, 21_000_000, 23_000_000, true, true) saleID := NewSale("TestFinalizeToken", "", startTimestamp, endTimestamp, 100, 15, 10, 20, true) onGoingSaleID := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp, 100, 15, 10, 20, true) - _ = NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp2, 100, 15, 10, 20, true) + onGoingSaleID2 := NewSale("TestFinalizeToken", "", startTimestamp, onGoingEndTimestamp2, 100, 15, 10, 20, true) realmCoins := std.NewCoins(std.NewCoin("ugnot", 200*10))