github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/wugnot/z0_filetest.gno (about)

     1  // PKGPATH: gno.land/r/demo/wugnot_test
     2  package wugnot_test
     3  
     4  import (
     5  	"fmt"
     6  	"std"
     7  
     8  	"gno.land/p/demo/testutils"
     9  	"gno.land/r/demo/wugnot"
    10  
    11  	pusers "gno.land/p/demo/users"
    12  )
    13  
    14  var (
    15  	addr1 = testutils.TestAddress("test1")
    16  	addrc = std.DerivePkgAddr("gno.land/r/demo/wugnot")
    17  	addrt = std.DerivePkgAddr("gno.land/r/demo/wugnot_test")
    18  )
    19  
    20  func main() {
    21  	std.TestSetOrigPkgAddr(addrc)
    22  	std.TestIssueCoins(addrc, std.Coins{{"ugnot", 100000001}}) // TODO: remove this
    23  
    24  	// issue ugnots
    25  	std.TestIssueCoins(addr1, std.Coins{{"ugnot", 100000001}})
    26  
    27  	// print initial state
    28  	printBalances()
    29  	// println(wugnot.Render("queues"))
    30  	// println("A -", wugnot.Render(""))
    31  
    32  	std.TestSetOrigCaller(addr1)
    33  	std.TestSetOrigSend(std.Coins{{"ugnot", 123_400}}, nil)
    34  	wugnot.Deposit()
    35  	printBalances()
    36  	wugnot.Withdraw(4242)
    37  	printBalances()
    38  }
    39  
    40  func printBalances() {
    41  	printSingleBalance := func(name string, addr std.Address) {
    42  		wugnotBal := wugnot.BalanceOf(pusers.AddressOrName(addr))
    43  		std.TestSetOrigCaller(addr)
    44  		abanker := std.GetBanker(std.BankerTypeOrigSend)
    45  		acoins := abanker.GetCoins(addr).AmountOf("ugnot")
    46  		bbanker := std.GetBanker(std.BankerTypeRealmIssue)
    47  		bcoins := bbanker.GetCoins(addr).AmountOf("ugnot")
    48  		cbanker := std.GetBanker(std.BankerTypeRealmSend)
    49  		ccoins := cbanker.GetCoins(addr).AmountOf("ugnot")
    50  		dbanker := std.GetBanker(std.BankerTypeReadonly)
    51  		dcoins := dbanker.GetCoins(addr).AmountOf("ugnot")
    52  		fmt.Printf("| %-13s | addr=%s | wugnot=%-5d | ugnot=%-9d %-9d %-9d %-9d |\n",
    53  			name, addr, wugnotBal, acoins, bcoins, ccoins, dcoins)
    54  	}
    55  	println("-----------")
    56  	printSingleBalance("wugnot_test", addrt)
    57  	printSingleBalance("wugnot", addrc)
    58  	printSingleBalance("addr1", addr1)
    59  	println("-----------")
    60  }
    61  
    62  // Output:
    63  // -----------
    64  // | wugnot_test   | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=0     | ugnot=200000000 200000000 200000000 200000000 |
    65  // | wugnot        | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0     | ugnot=100000001 100000001 100000001 100000001 |
    66  // | addr1         | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0     | ugnot=100000001 100000001 100000001 100000001 |
    67  // -----------
    68  // -----------
    69  // | wugnot_test   | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=123400 | ugnot=200000000 200000000 200000000 200000000 |
    70  // | wugnot        | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0     | ugnot=100000001 100000001 100000001 100000001 |
    71  // | addr1         | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0     | ugnot=100000001 100000001 100000001 100000001 |
    72  // -----------
    73  // -----------
    74  // | wugnot_test   | addr=g19rmydykafrqyyegc8uuaxxpzqwzcnxraj2dev9 | wugnot=119158 | ugnot=200004242 200004242 200004242 200004242 |
    75  // | wugnot        | addr=g1pf6dv9fjk3rn0m4jjcne306ga4he3mzmupfjl6 | wugnot=0     | ugnot=99995759  99995759  99995759  99995759  |
    76  // | addr1         | addr=g1w3jhxap3ta047h6lta047h6lta047h6l4mfnm7 | wugnot=0     | ugnot=100000001 100000001 100000001 100000001 |
    77  // -----------