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
842 stars 343 forks source link

Unable to call modifying methods on types imported from other realms #1671

Open deelawn opened 4 months ago

deelawn commented 4 months ago

I'm not sure this is a problem but it could use further explanation. I was looking at an issue @leohhhn brought up regarding an error he was getting when trying to add a post to a blog. In summary, the issue was:

I wrote a txtar script to exemplify the issue:

gnoland start

gnokey maketx addpkg -pkgdir $WORK/blogtest -pkgpath gno.land/r/blogtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
gnokey maketx addpkg -pkgdir $WORK/owner -pkgpath gno.land/r/owner -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

gnokey maketx call -pkgpath gno.land/r/owner -func AddPost -args 'my first post' -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

-- owner/blog.gno --
package owner

import blog "gno.land/r/blogtest"

var Blog = new(blog.Blog)

func AddPost(title string) {
    Blog.AddPost(title)
}

func GetPost() blog.Post {
    return Blog.Post
}

-- blogtest/blog.gno --
package blogtest

type Blog struct {
    Post  Post
}

type Post struct {
    Title string
}

func (b *Blog) AddPost(title string) {
    b.Post = Post{title}
}

In the case above the error will happen when calling AddPost from the owner realm. I'm not sure why this isn't allowed because the only object being modified is that which is owned by the owner realm, so it isn't as if this call is modifying another realm's state.

deelawn commented 4 months ago

This may be addressed by #1257. Will check to confirm