gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
875 stars 355 forks source link

Support `std.GetOrigPkgAddr()` in init() function (tests) #656

Open albttx opened 1 year ago

albttx commented 1 year ago

When you create a Token, or anything that require the Realm to have his own treasury, the best would be in the init() function to be able to do:

var foo *grc20.AdminToken

func init() {
    foo = grc20.NewAdminToken("Foo", "FOO", 4)
    foo.Mint(std.GetOrigPkgAddr(), 1000000)
}

Which is not possibe at the moment because the the (m *Machine).Context is nil in std.GetOrigPkgAddr.

albttx commented 1 year ago

EDIT: this is just a go test problem, running with gnodev works perfectly

albttx commented 1 year ago

Issue is because TestStore() is creating a *Machine, so we loose the (*m.Machine).Context

https://github.com/gnolang/gno/blob/master/tests/imports.go#L100-L106

And then call m2.RunMemPackage()