Skip to content

Commit

Permalink
chore: add dummy filetest examples
Browse files Browse the repository at this point in the history
Signed-off-by: moul <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed Sep 18, 2024
1 parent 9103465 commit 07c51b1
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
66 changes: 66 additions & 0 deletions examples/gno.land/r/demo/gnofundme/z_1_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SEND: 1234567890ugnot
package main

import "std"

func main() {
banktestAddr := std.DerivePkgAddr("gno.land/r/demo/gnofundme")
mainaddr := std.DerivePkgAddr("main")
std.TestSetOrigCaller(mainaddr)
std.TestSetOrigPkgAddr(banktestAddr)
banker := std.GetBanker(std.BankerTypeRealmSend)
mainbal := banker.GetCoins(mainaddr)
println(mainbal)
/*
// Setup
// get and print balance of mainaddr.
// with the SEND, + 200 gnot given by the TestContext, main should have 300gnot.
ctype := 0
title := "Campaign for Withdrawal"
description := "Description for Withdrawal"
goal := int64(1000)
begin := time.Now()
deadline := begin.Add(time.Second * 1)
ownerAddress := testutils.TestAddress("owner")
beneficiaryAddress := testutils.TestAddress("beneficiary")
std.TestSetOrigCaller(beneficiaryAddress)
NewUser("Beneficiary", "")
std.TestSetOrigCaller(ownerAddress)
NewUser("Owner", "")
NewCampaign(ctype, title, description, goal, begin.Unix(), deadline.Unix(), beneficiaryAddress)
// Add contributions to the campaign
contributorAddress := testutils.TestAddress("contributor")
std.TestSetOrigCaller(contributorAddress)
NewUser("Contributor", "")
var amount int64 = 500
display := true
// date := time.Unix(time.Now().Unix(), 0)
banker.SendCoins(banktestAddr, mainaddr, std.Coins{{"ugnot", 500}})
std.TestSetOrigSend(std.Coins{{"ugnot", 500}}, nil)
AddContributor("0", display)
// Fast forward time to after the campaign deadline
// Simulate time passing
// time.Sleep(time.Second * 2)
// deadline = time.Now().Add(-time.Second * 1)
std.TestSetOrigCaller(ownerAddress)
std.TestSkipHeights(1)
// Withdraw funds
Withdraw("0")
// Verify
if campaignsTotal["0"] != 0 {
t.Errorf("Expected campaignsTotal to be 0 after withdrawal, got %d", campaignsTotal["0"])
}
beneficiaryBalance := banker.GetCoins(beneficiaryAddress).AmountOf("ugnot")
if beneficiaryBalance != amount {
t.Errorf("Expected beneficiary balance to be %d, got %d", amount, beneficiaryBalance)
}
*/
}

// Output:
// 1434567890ugnot
66 changes: 66 additions & 0 deletions examples/gno.land/r/demo/gnofundme/z_2_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SEND: 1234567890ugnot
package main

import "std"

func main() {
banktestAddr := std.DerivePkgAddr("gno.land/r/demo/gnofundme")
mainaddr := std.DerivePkgAddr("main")
std.TestSetOrigCaller(mainaddr)
std.TestSetOrigPkgAddr(banktestAddr)
banker := std.GetBanker(std.BankerTypeRealmSend)
mainbal := banker.GetCoins(mainaddr)
println(mainbal)
/*
// Setup
// get and print balance of mainaddr.
// with the SEND, + 200 gnot given by the TestContext, main should have 300gnot.
ctype := 0
title := "Campaign for Withdrawal"
description := "Description for Withdrawal"
goal := int64(1000)
begin := time.Now()
deadline := begin.Add(time.Second * 1)
ownerAddress := testutils.TestAddress("owner")
beneficiaryAddress := testutils.TestAddress("beneficiary")
std.TestSetOrigCaller(beneficiaryAddress)
NewUser("Beneficiary", "")
std.TestSetOrigCaller(ownerAddress)
NewUser("Owner", "")
NewCampaign(ctype, title, description, goal, begin.Unix(), deadline.Unix(), beneficiaryAddress)
// Add contributions to the campaign
contributorAddress := testutils.TestAddress("contributor")
std.TestSetOrigCaller(contributorAddress)
NewUser("Contributor", "")
var amount int64 = 500
display := true
// date := time.Unix(time.Now().Unix(), 0)
banker.SendCoins(banktestAddr, mainaddr, std.Coins{{"ugnot", 500}})
std.TestSetOrigSend(std.Coins{{"ugnot", 500}}, nil)
AddContributor("0", display)
// Fast forward time to after the campaign deadline
// Simulate time passing
// time.Sleep(time.Second * 2)
// deadline = time.Now().Add(-time.Second * 1)
std.TestSetOrigCaller(ownerAddress)
std.TestSkipHeights(1)
// Withdraw funds
Withdraw("0")
// Verify
if campaignsTotal["0"] != 0 {
t.Errorf("Expected campaignsTotal to be 0 after withdrawal, got %d", campaignsTotal["0"])
}
beneficiaryBalance := banker.GetCoins(beneficiaryAddress).AmountOf("ugnot")
if beneficiaryBalance != amount {
t.Errorf("Expected beneficiary balance to be %d, got %d", amount, beneficiaryBalance)
}
*/
}

// Output:
// 1434567890ugnot

0 comments on commit 07c51b1

Please sign in to comment.