Skip to content

Commit

Permalink
test: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s authored and onlyhyde committed Jan 8, 2025
1 parent 323749b commit 158d843
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 7 additions & 1 deletion launchpad/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import (

"gno.land/p/demo/grc/grc20"
"gno.land/p/demo/testutils"
"gno.land/p/demo/ufmt"
pusers "gno.land/p/demo/users"
"gno.land/r/demo/users"
"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/consts"
)

var (
adminAddr = consts.ADMIN
adminUser = common.AddrToUser(adminAddr)
adminRealm = std.NewUserRealm(adminAddr)
)

// MockXGNSToken implements basic functionality for testing xgns token
type MockXGNSToken struct {
token *grc20.Token
Expand Down
14 changes: 9 additions & 5 deletions launchpad/deposit_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package launchpad

import (
"std"
"strings"
"testing"
"time"

"gno.land/p/demo/testutils"
"gno.land/p/demo/uassert"
"gno.land/p/demo/ufmt"

"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/consts"
"gno.land/r/gnoswap/v1/gov/xgns"

"gno.land/r/gnoswap/v1/gns"
)

// Mock data structs
Expand Down Expand Up @@ -320,21 +321,24 @@ func TestDepositGns(t *testing.T) {

t.Run("Fail with insufficient balance", func(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(testAddr))
mockTeller.balance = 500 // Less than required deposit amount

defer func() {
r := recover()
if r != nil {
t.Fatalf("Recovered from panic: %v", r)
t.Logf("Recovered from panic: %v", r)
}
}()

DepositGns(project.id+":30", 1000)
})

t.Run("Success with sufficient balance", func(t *testing.T) {
// transfer enough gns
std.TestSetRealm(adminRealm)
gns.Transfer(common.AddrToUser(testAddr), 1000)

std.TestSetRealm(std.NewUserRealm(testAddr))
mockTeller.balance = 2000 // More than required deposit amount
gns.Approve(common.AddrToUser(consts.LAUNCHPAD_ADDR), 1000)

depositId := DepositGns(project.id+":30", 1000)
deposit := deposits[depositId]
Expand Down

0 comments on commit 158d843

Please sign in to comment.