Skip to content

Commit

Permalink
refactor: std.TestSetOrigSend => t.SetOriginSend, testing.SetOriginSe…
Browse files Browse the repository at this point in the history
…nd + remove X_testSetOrigSend
  • Loading branch information
hthieu1110 committed Jan 25, 2025
1 parent 0488bc6 commit 8975f59
Show file tree
Hide file tree
Showing 31 changed files with 76 additions and 124 deletions.
10 changes: 5 additions & 5 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ func TestFull(t *testing.T) {
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))

std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
shouldPanic(t, Bid)
}

// Send less than the highest bid
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}}, nil)
shouldPanic(t, Bid)
}

// Send more than the highest bid
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)

shouldEqual(t, pendingReturns.Size(), 0)
Expand All @@ -44,12 +44,12 @@ func TestFull(t *testing.T) {

// Send less amount than the current highest bid (current: 1)
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldPanic(t, Bid)

// Send more amount than the current highest bid (exceeded)
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 2}}, nil)
shouldNoPanic(t, Bid)

shouldEqual(t, highestBid, 2)
Expand Down
12 changes: 6 additions & 6 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
func TestBidCoins(t *testing.T) {
// Sending two types of coins
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
shouldPanic(t, Bid)

// Sending lower amount than the current highest bid
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}}, nil)
shouldPanic(t, Bid)

// Sending more amount than the current highest bid (exceeded)
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)
}

// Bid Function Test - Bid by two or more people
func TestBidCoins(t *testing.T) {
// bidder01 bidding with 1 coin
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)
shouldEqual(t, highestBid, 1)
shouldEqual(t, highestBidder, bidder01)
shouldEqual(t, pendingReturns.Size(), 0)

// bidder02 bidding with 1 coin
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldPanic(t, Bid)

// bidder02 bidding with 2 coins
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 2}}, nil)
shouldNoPanic(t, Bid)
shouldEqual(t, highestBid, 2)
shouldEqual(t, highestBidder, bidder02)
Expand Down
22 changes: 11 additions & 11 deletions docs/how-to-guides/porting-solidity-to-gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,38 +389,38 @@ func TestBidCoins(t *testing.T) {
// Sending two types of coins
t.SetPreviousRealm(std.NewUserRealm(bidder01))

std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
shouldPanic(t, Bid)

// Sending lower amount than the current highest bid
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}}, nil)
shouldPanic(t, Bid)

// Sending more amount than the current highest bid (exceeded)
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)
}

// Bid Function Test - Bid by two or more people
func TestBidCoins(t *testing.T) {
// bidder01 bidding with 1 coin
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)
shouldEqual(t, highestBid, 1)
shouldEqual(t, highestBidder, bidder01)
shouldEqual(t, pendingReturns.Size(), 0)

// bidder02 bidding with 1 coin
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldPanic(t, Bid)

// bidder02 bidding with 2 coins
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 2}}, nil)
shouldNoPanic(t, Bid)
shouldEqual(t, highestBid, 2)
shouldEqual(t, highestBidder, bidder02)
Expand Down Expand Up @@ -622,21 +622,21 @@ func TestFull(t *testing.T) {
// Send two or more types of coins
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil)
shouldPanic(t, Bid)
}

// Send less than the highest bid
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 0}}, nil)
shouldPanic(t, Bid)
}

// Send more than the highest bid
{
t.SetPreviousRealm(std.NewUserRealm(bidder01))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldNoPanic(t, Bid)

shouldEqual(t, pendingReturns.Size(), 0)
Expand All @@ -649,12 +649,12 @@ func TestFull(t *testing.T) {

// Send less amount than the current highest bid (current: 1)
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 1}}, nil)
shouldPanic(t, Bid)

// Send more amount than the current highest bid (exceeded)
t.SetPreviousRealm(std.NewUserRealm(bidder02))
std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil)
t.SetOriginSend(std.Coins{{"ugnot", 2}}, nil)
shouldNoPanic(t, Bid)

shouldEqual(t, highestBid, 2)
Expand Down
10 changes: 5 additions & 5 deletions examples/gno.land/p/demo/simpledao/dao_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSimpleDAO_Propose(t *testing.T) {
s = New(ms)
)

std.TestSetOrigSend(sentCoins, std.Coins{})
t.SetOriginSend(sentCoins, std.Coins{})

_, err := s.Propose(dao.ProposalRequest{
Executor: ex,
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestSimpleDAO_Propose(t *testing.T) {

// Set the sent coins to be lower
// than the proposal fee
std.TestSetOrigSend(sentCoins, std.Coins{})
t.SetOriginSend(sentCoins, std.Coins{})

_, err := s.Propose(dao.ProposalRequest{
Executor: ex,
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestSimpleDAO_Propose(t *testing.T) {

// Set the sent coins to be enough
// to cover the fee
std.TestSetOrigSend(sentCoins, std.Coins{})
t.SetOriginSend(sentCoins, std.Coins{})
t.SetPreviousRealm(std.NewUserRealm(proposer))

// Make sure the proposal was added
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) {

// Set the sent coins to be lower
// than the execute fee
std.TestSetOrigSend(sentCoins, std.Coins{})
t.SetOriginSend(sentCoins, std.Coins{})

uassert.ErrorIs(
t,
Expand Down Expand Up @@ -699,7 +699,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) {

// Set the sent coins to be enough
// so the execution can take place
std.TestSetOrigSend(sentCoins, std.Coins{})
t.SetOriginSend(sentCoins, std.Coins{})

uassert.ErrorContains(
t,
Expand Down
16 changes: 8 additions & 8 deletions examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLifetimeSubscription(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(alice))
ls := NewLifetimeSubscription(1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := ls.Subscribe()
uassert.NoError(t, err, "Expected ProcessPayment to succeed")

Expand All @@ -30,7 +30,7 @@ func TestLifetimeSubscriptionGift(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(alice))
ls := NewLifetimeSubscription(1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := ls.GiftSubscription(bob)
uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob")

Expand Down Expand Up @@ -58,7 +58,7 @@ func TestIncorrectPaymentAmount(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
ls := NewLifetimeSubscription(1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
err := ls.Subscribe()
uassert.Error(t, err, "Expected payment to fail with incorrect amount")
}
Expand All @@ -67,11 +67,11 @@ func TestMultipleSubscriptionAttempts(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
ls := NewLifetimeSubscription(1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := ls.Subscribe()
uassert.NoError(t, err, "Expected first subscription to succeed")

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err = ls.Subscribe()
uassert.Error(t, err, "Expected second subscription to fail as Alice is already subscribed")
}
Expand All @@ -80,7 +80,7 @@ func TestGiftSubscriptionWithIncorrectAmount(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
ls := NewLifetimeSubscription(1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
err := ls.GiftSubscription(bob)
uassert.Error(t, err, "Expected gift subscription to fail with incorrect amount")

Expand All @@ -95,11 +95,11 @@ func TestUpdateAmountEffectiveness(t *testing.T) {
err := ls.UpdateAmount(2000)
uassert.NoError(t, err, "Expected Alice to succeed in updating amount")

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err = ls.Subscribe()
uassert.Error(t, err, "Expected subscription to fail with old amount after update")

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}, nil)
err = ls.Subscribe()
uassert.NoError(t, err, "Expected subscription to succeed with new amount")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestRecurringSubscription(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour*24, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := rs.Subscribe()
uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice")

Expand All @@ -34,7 +34,7 @@ func TestRecurringSubscriptionGift(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour*24, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := rs.GiftSubscription(bob)
uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob")

Expand All @@ -49,7 +49,7 @@ func TestRecurringSubscriptionExpiration(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := rs.Subscribe()
uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice")

Expand Down Expand Up @@ -93,7 +93,7 @@ func TestIncorrectPaymentAmount(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour*24, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil)
err := rs.Subscribe()
uassert.Error(t, err, "Expected payment with incorrect amount to fail")
}
Expand All @@ -102,11 +102,11 @@ func TestMultiplePaymentsForSameUser(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour*24, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := rs.Subscribe()
uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice")

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err = rs.Subscribe()
uassert.Error(t, err, "Expected second ProcessPayment to fail for Alice due to existing subscription")
}
Expand All @@ -115,7 +115,7 @@ func TestRecurringSubscriptionWithMultiplePayments(t *testing.T) {
t.SetPreviousRealm(std.NewUserRealm(alice))
rs := NewRecurringSubscription(time.Hour, 1000)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err := rs.Subscribe()
uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice")

Expand All @@ -125,7 +125,7 @@ func TestRecurringSubscriptionWithMultiplePayments(t *testing.T) {
expiration := time.Now().Add(-time.Hour * 2)
rs.subs.Set(std.PrevRealm().Addr().String(), expiration)

std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil)
err = rs.Subscribe()
uassert.NoError(t, err, "Expected second ProcessPayment to succeed for Alice")

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/atomicswap/atomicswap_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestNewCustomCoinSwap_Claim(t *testing.T) {

// Create a new swap
std.TestSetRealm(std.NewUserRealm(sender))
std.TestSetOrigSend(amount, nil)
t.SetOriginSend(amount, nil)
id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock)
uassert.Equal(t, 1, id)

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestNewCustomCoinSwap_Refund(t *testing.T) {

// Create a new swap
std.TestSetRealm(std.NewUserRealm(sender))
std.TestSetOrigSend(amount, nil)
t.SetOriginSend(amount, nil)
id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock) // Create a new swap
uassert.Equal(t, 1, id)

Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/banktest/z_0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {

// simulate a Deposit call. use Send + OrigSend to simulate -send.
banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil)
testing.SetOriginSend(std.Coins{{"ugnot", 100_000_000}}, nil)
res := banktest.Deposit("ugnot", 50_000_000)
println("Deposit():", res)

Expand Down
3 changes: 2 additions & 1 deletion examples/gno.land/r/demo/banktest/z_1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bank1

import (
"std"
"testing"

"gno.land/r/demo/banktest"
)
Expand All @@ -17,7 +18,7 @@ func main() {
// simulate a Deposit call.
std.TestSetOrigPkgAddr(banktestAddr)
std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil)
testing.SetOriginSend(std.Coins{{"ugnot", 100000000}}, nil)
res := banktest.Deposit("ugnot", 101000000)
println(res)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/banktest/z_2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
// simulate a Deposit call.
std.TestSetOrigPkgAddr(banktestAddr)
std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}})
std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil)
testing.SetOriginSend(std.Coins{{"ugnot", 100000000}}, nil)
res := banktest.Deposit("ugnot", 55000000)
println("Deposit():", res)

Expand Down
Loading

0 comments on commit 8975f59

Please sign in to comment.