-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stdlibs/std): restrict Banker methods based on caller of GetBank…
…er (#1921) related pr #1787 There was bit of extra conversion in previous pr after merged. 1) revert test cases 2) allow `Send` from realm that created banker rather the one calling <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <git@howl.moe>
- Loading branch information
Showing
8 changed files
with
77 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
package main | ||
|
||
// NOTE: this doesn't do anything, as it sends to "main". | ||
// SEND: 100000000ugnot | ||
|
||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/demo/banktest" | ||
) | ||
|
||
func main() { | ||
// set up main address and banktest addr. | ||
banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") | ||
|
||
// print main balance before. | ||
mainaddr := std.DerivePkgAddr("main") | ||
std.TestSetOrigCaller(mainaddr) | ||
std.TestSetOrigPkgAddr(banktestAddr) | ||
|
||
banker := std.GetBanker(std.BankerTypeReadonly) | ||
// get and print balance of mainaddr. | ||
// with the SEND, + 200 gnot given by the TestContext, main should have 300gnot. | ||
banker := std.GetBanker(std.BankerTypeRealmSend) | ||
mainbal := banker.GetCoins(mainaddr) | ||
println("main before:", mainbal) // plus OrigSend equals 300. | ||
println("main before:", mainbal) | ||
|
||
// simulate a Deposit call. | ||
std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) | ||
std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) | ||
res := banktest.Deposit("ugnot", 100000000) | ||
// 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) | ||
res := banktest.Deposit("ugnot", 50_000_000) | ||
println("Deposit():", res) | ||
|
||
// print main balance after. | ||
mainbal = banker.GetCoins(mainaddr) | ||
println("main after:", mainbal) // still 300. | ||
println("main after:", mainbal) | ||
|
||
// simulate a Render(). | ||
// simulate a Render(). banker should have given back all coins. | ||
res = banktest.Render("") | ||
println(res) | ||
} | ||
|
||
// Output: | ||
// main before: 200000000ugnot | ||
// main before: 300000000ugnot | ||
// Deposit(): returned! | ||
// main after: 300000000ugnot | ||
// main after: 250000000ugnot | ||
// ## recent activity | ||
// | ||
// * g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 100000000ugnot sent, 100000000ugnot returned, at 2009-02-13 11:31pm UTC | ||
// * g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4 100000000ugnot sent, 50000000ugnot returned, at 2009-02-13 11:31pm UTC | ||
// | ||
// ## total deposits | ||
// 300000000ugnot | ||
// 50000000ugnot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
) | ||
|
||
func main() { | ||
banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") | ||
|
||
mainaddr := std.DerivePkgAddr("main") | ||
std.TestSetOrigCaller(mainaddr) | ||
|
||
banker := std.GetBanker(std.BankerTypeRealmSend) | ||
send := std.Coins{{"ugnot", 123}} | ||
banker.SendCoins(banktestAddr, mainaddr, send) | ||
|
||
} | ||
|
||
// Error: | ||
// can only send coins from realm that created banker "g17rgsdnfxzza0sdfsdma37sdwxagsz378833ca4", not "g1dv3435088tlrgggf745kaud0ptrkc9v42k8llz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters