Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

newtoken_event_filetest.gno

2.92 Kb · 116 lines
  1// PKGPATH: gno.land/r/demo/grc721dupsignal
  2
  3// This filetest is the reference for the detection rule the NewToken event
  4// enables. The realm below reuses seqid 0 twice, so both tokens end up with the
  5// same Token.ID() and their Transfer events are indistinguishable — the
  6// long-standing event-provenance ambiguity.
  7//
  8// What changes is that the ambiguity is now *announced*. Two NewToken events
  9// carry the same "token" value, which is a complete signal: NewToken is the only
 10// way a Token can exist (Token's fields are unexported), so an indexer watching
 11// this event sees every token that will ever emit. On the second duplicate
 12// announcement it should flag the realm and stop trusting its token events.
 13package grc721dupsignal
 14
 15import (
 16	"gno.land/p/nt/grc721/v0"
 17)
 18
 19func main(cur realm) {
 20	first, firstLedger := grc721.NewToken("Same", "DUP", 0, cur)
 21	second, secondLedger := grc721.NewToken("Same", "DUP", 0, cur)
 22
 23	println("same id:", first.ID() == second.ID())
 24
 25	// Two independent ledgers, one identifier: these Transfers cannot be
 26	// attributed to either object from the event stream alone.
 27	firstLedger.Mint(cur.Address(), "1")
 28	secondLedger.Mint(cur.Address(), "2")
 29}
 30
 31// Output:
 32// same id: true
 33
 34// Events:
 35// [
 36//   {
 37//     "type": "NewToken",
 38//     "attrs": [
 39//       {
 40//         "key": "token",
 41//         "value": "gno.land/r/demo/grc721dupsignal.DUP.0000000"
 42//       },
 43//       {
 44//         "key": "name",
 45//         "value": "Same"
 46//       },
 47//       {
 48//         "key": "symbol",
 49//         "value": "DUP"
 50//       }
 51//     ],
 52//     "pkg_path": "gno.land/p/nt/grc721/v0"
 53//   },
 54//   {
 55//     "type": "NewToken",
 56//     "attrs": [
 57//       {
 58//         "key": "token",
 59//         "value": "gno.land/r/demo/grc721dupsignal.DUP.0000000"
 60//       },
 61//       {
 62//         "key": "name",
 63//         "value": "Same"
 64//       },
 65//       {
 66//         "key": "symbol",
 67//         "value": "DUP"
 68//       }
 69//     ],
 70//     "pkg_path": "gno.land/p/nt/grc721/v0"
 71//   },
 72//   {
 73//     "type": "Transfer",
 74//     "attrs": [
 75//       {
 76//         "key": "token",
 77//         "value": "gno.land/r/demo/grc721dupsignal.DUP.0000000"
 78//       },
 79//       {
 80//         "key": "from",
 81//         "value": ""
 82//       },
 83//       {
 84//         "key": "to",
 85//         "value": "g1f2p7p8jhjmg6atgukt8kveqgsrrk3qqhe6vg9m"
 86//       },
 87//       {
 88//         "key": "tokenId",
 89//         "value": "1"
 90//       }
 91//     ],
 92//     "pkg_path": "gno.land/p/nt/grc721/v0"
 93//   },
 94//   {
 95//     "type": "Transfer",
 96//     "attrs": [
 97//       {
 98//         "key": "token",
 99//         "value": "gno.land/r/demo/grc721dupsignal.DUP.0000000"
100//       },
101//       {
102//         "key": "from",
103//         "value": ""
104//       },
105//       {
106//         "key": "to",
107//         "value": "g1f2p7p8jhjmg6atgukt8kveqgsrrk3qqhe6vg9m"
108//       },
109//       {
110//         "key": "tokenId",
111//         "value": "2"
112//       }
113//     ],
114//     "pkg_path": "gno.land/p/nt/grc721/v0"
115//   }
116// ]