Skip to content
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

test(gno/launchpad-E/GRC20): adapt test by adding coins to realm #1466

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading