github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/x/test_prev/test_prev_test.gno (about)

     1  package test_prev
     2  
     3  import (
     4  	"std"
     5  	"testing"
     6  
     7  	"gno.land/r/demo/foo20"
     8  )
     9  
    10  func TestDoSomeWithUserBalancePoor(t *testing.T) {
    11  	std.TestSetOrigCaller("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
    12  	if DoSomeWithUserBalance() != "poor user" {
    13  		t.Error("expected poor user")
    14  	}
    15  }
    16  
    17  func TestDoSomeWithUserBalanceRichButPoor(t *testing.T) {
    18  	std.TestSetOrigCaller("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
    19  	foo20.Faucet() // foo20 will mint tokens to this realm(std.PrevRealm) not user
    20  	if DoSomeWithUserBalance() != "poor user" {
    21  		t.Error("expected poor user")
    22  	}
    23  }
    24  
    25  func TestDoSomeWithUserBalanceRich(t *testing.T) {
    26  	std.TestSetPrevAddr("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
    27  
    28  	foo20.Faucet() // foo20 will mint tokens to this realm not user
    29  	if DoSomeWithUserBalance() != "rich user" {
    30  		t.Error("expected rich user")
    31  	}
    32  }