Skip to content

Commit

Permalink
test(gno/launchpad-E/GRC20): adapt test by adding coins to realm (#1466)
Browse files Browse the repository at this point in the history
Co-authored-by: n0izn0iz <[email protected]>
  • Loading branch information
MikaelVallenet and n0izn0iz authored Jan 2, 2025
1 parent 7796e47 commit 099df17
Showing 1 changed file with 43 additions and 45 deletions.
88 changes: 43 additions & 45 deletions gno/r/launchpad_grc20/sale_grc20_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ 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))

tests := testBuyTestTable{
"Success": {
Expand Down Expand Up @@ -457,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 @@ -487,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 @@ -535,7 +535,9 @@ 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))

tests := testFinalizeTestTable{
"Success with 0 tokens sold": {
Expand Down Expand Up @@ -582,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 @@ -631,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 099df17

Please sign in to comment.