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

newtoken_event_filetest.gno

3.09 Kb · 124 lines
  1// PKGPATH: gno.land/r/demo/grc20dupsignal
  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 grc20dupsignal
 14
 15import (
 16	"gno.land/p/demo/tokens/grc20"
 17)
 18
 19func main(cur realm) {
 20	first, firstLedger := grc20.NewToken("Same", "DUP", 6, 0, cur)
 21	second, secondLedger := grc20.NewToken("Same", "DUP", 6, 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(), 999999)
 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/grc20dupsignal.DUP.0000000"
 42//       },
 43//       {
 44//         "key": "name",
 45//         "value": "Same"
 46//       },
 47//       {
 48//         "key": "symbol",
 49//         "value": "DUP"
 50//       },
 51//       {
 52//         "key": "decimals",
 53//         "value": "6"
 54//       }
 55//     ],
 56//     "pkg_path": "gno.land/p/demo/tokens/grc20"
 57//   },
 58//   {
 59//     "type": "NewToken",
 60//     "attrs": [
 61//       {
 62//         "key": "token",
 63//         "value": "gno.land/r/demo/grc20dupsignal.DUP.0000000"
 64//       },
 65//       {
 66//         "key": "name",
 67//         "value": "Same"
 68//       },
 69//       {
 70//         "key": "symbol",
 71//         "value": "DUP"
 72//       },
 73//       {
 74//         "key": "decimals",
 75//         "value": "6"
 76//       }
 77//     ],
 78//     "pkg_path": "gno.land/p/demo/tokens/grc20"
 79//   },
 80//   {
 81//     "type": "Transfer",
 82//     "attrs": [
 83//       {
 84//         "key": "token",
 85//         "value": "gno.land/r/demo/grc20dupsignal.DUP.0000000"
 86//       },
 87//       {
 88//         "key": "from",
 89//         "value": ""
 90//       },
 91//       {
 92//         "key": "to",
 93//         "value": "g1k29lxz0d8gx7m94n032ulum875p7gg0kduus5m"
 94//       },
 95//       {
 96//         "key": "value",
 97//         "value": "1"
 98//       }
 99//     ],
100//     "pkg_path": "gno.land/p/demo/tokens/grc20"
101//   },
102//   {
103//     "type": "Transfer",
104//     "attrs": [
105//       {
106//         "key": "token",
107//         "value": "gno.land/r/demo/grc20dupsignal.DUP.0000000"
108//       },
109//       {
110//         "key": "from",
111//         "value": ""
112//       },
113//       {
114//         "key": "to",
115//         "value": "g1k29lxz0d8gx7m94n032ulum875p7gg0kduus5m"
116//       },
117//       {
118//         "key": "value",
119//         "value": "999999"
120//       }
121//     ],
122//     "pkg_path": "gno.land/p/demo/tokens/grc20"
123//   }
124// ]