Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z5abb_transfer_grc20_confused_deputy_filetest.gno

1.38 Kb · 41 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4// Regression test: a non-IBC GRC20 Transfer initiated by a non-user caller
 5// must be rejected even when the user has granted the transfer app allowance.
 6
 7import (
 8	"chain"
 9	"time"
10
11	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
12	"gno.land/p/aib/ibc/types"
13
14	"gno.land/r/aib/ibc/apps/testing/grc20test"
15	"gno.land/r/aib/ibc/apps/transfer"
16	"gno.land/r/aib/ibc/core"
17)
18
19func main(cur realm) {
20	var (
21		chainID        = "chain-id-2"
22		clientState    = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
23		apphash        = tmtesting.Hash("apphash")
24		trustedValset  = tmtesting.GenValset()
25		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
26	)
27	clientID := core.CreateClient(cross(cur), clientState, consensusState)
28	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
29
30	owner := cur.Previous().Address()
31
32	grc20test.Mint(cross(cur), owner, 1000)
33	transferAppAddr := chain.PackageAddress("gno.land/r/aib/ibc/apps/transfer")
34	grc20test.Approve(cross(cur), owner, transferAppAddr, 100)
35
36	denom := "gno.land/r/aib/ibc/apps/testing/grc20test." + grc20test.Slug
37	transfer.Transfer(cross(cur), clientID, "atone1user", denom, 100, uint64(time.Now().Add(time.Hour).Unix()), "")
38}
39
40// Error:
41// GRC20 transfer must be a direct user call (maketx call)