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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

z_events_filetest.gno

6.35 Kb · 251 lines
  1// PKGPATH: gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate/filetests/z_events_filetest
  2
  3// Every state change emits an event. Pulled, CreditDropped and the paid-time
  4// values (kept, carried) above 0 need a Pull, which only a session-signed
  5// transaction can reach; scripts/local-flow.sh checks them on a real chain.
  6package z_events_filetest
  7
  8import (
  9	"testing"
 10	"time"
 11
 12	"gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
 13)
 14
 15const (
 16	payee = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
 17	payer = address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // test2
 18	gpub  = "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pqfp0696ldln2nm7kd33zfpgypg6u0e7upl03hyeexa6mccn4ce8mkswg65c"
 19	sess  = address("g1psdsf789f4xw3qrpjue54g2h28syd09yfkrxdh")
 20)
 21
 22func main(cur realm) {
 23	testing.SetRealm(testing.NewUserRealm(payee))
 24	id := mandate.Offer(cross(cur), "Weekly supporter", 1_000_000, 604800)
 25	testing.SetRealm(testing.NewUserRealm(payee))
 26	mandate.SetCollectorKey(cross(cur), gpub)
 27	testing.SetRealm(testing.NewUserRealm(payer))
 28	mandate.Subscribe(cross(cur), id, sess, time.Now().Unix()+86400)
 29	testing.SetRealm(testing.NewUserRealm(payer))
 30	mandate.Cancel(cross(cur), payer, sess)
 31	println(mandate.HasMandate(payer, id))
 32	// an expired mandate is dropped at its payer's next Subscribe
 33	testing.SetRealm(testing.NewUserRealm(payer))
 34	mandate.Subscribe(cross(cur), id, sess, time.Now().Unix()+60)
 35	testing.SkipHeights(13)
 36	testing.SetRealm(testing.NewUserRealm(payer))
 37	mandate.Subscribe(cross(cur), id, sess, time.Now().Unix()+86400)
 38}
 39
 40// Output:
 41// false
 42
 43// Events:
 44// [
 45//   {
 46//     "type": "PlanOffered",
 47//     "attrs": [
 48//       {
 49//         "key": "plan",
 50//         "value": "1"
 51//       },
 52//       {
 53//         "key": "payee",
 54//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
 55//       },
 56//       {
 57//         "key": "title",
 58//         "value": "Weekly supporter"
 59//       },
 60//       {
 61//         "key": "amount",
 62//         "value": "1000000"
 63//       },
 64//       {
 65//         "key": "period",
 66//         "value": "604800"
 67//       }
 68//     ],
 69//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
 70//   },
 71//   {
 72//     "type": "CollectorKeySet",
 73//     "attrs": [
 74//       {
 75//         "key": "payee",
 76//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
 77//       },
 78//       {
 79//         "key": "pubkey",
 80//         "value": "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pqfp0696ldln2nm7kd33zfpgypg6u0e7upl03hyeexa6mccn4ce8mkswg65c"
 81//       },
 82//       {
 83//         "key": "address",
 84//         "value": "g1psdsf789f4xw3qrpjue54g2h28syd09yfkrxdh"
 85//       }
 86//     ],
 87//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
 88//   },
 89//   {
 90//     "type": "Subscribed",
 91//     "attrs": [
 92//       {
 93//         "key": "mandate",
 94//         "value": "1"
 95//       },
 96//       {
 97//         "key": "plan",
 98//         "value": "1"
 99//       },
100//       {
101//         "key": "payer",
102//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
103//       },
104//       {
105//         "key": "payee",
106//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
107//       },
108//       {
109//         "key": "session",
110//         "value": "g1psdsf789f4xw3qrpjue54g2h28syd09yfkrxdh"
111//       },
112//       {
113//         "key": "expires",
114//         "value": "1234654290"
115//       },
116//       {
117//         "key": "first",
118//         "value": "1234567890"
119//       },
120//       {
121//         "key": "carried",
122//         "value": "0"
123//       }
124//     ],
125//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
126//   },
127//   {
128//     "type": "Cancelled",
129//     "attrs": [
130//       {
131//         "key": "mandate",
132//         "value": "1"
133//       },
134//       {
135//         "key": "plan",
136//         "value": "1"
137//       },
138//       {
139//         "key": "payer",
140//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
141//       },
142//       {
143//         "key": "by",
144//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
145//       },
146//       {
147//         "key": "kept",
148//         "value": "0"
149//       }
150//     ],
151//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
152//   },
153//   {
154//     "type": "Subscribed",
155//     "attrs": [
156//       {
157//         "key": "mandate",
158//         "value": "2"
159//       },
160//       {
161//         "key": "plan",
162//         "value": "1"
163//       },
164//       {
165//         "key": "payer",
166//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
167//       },
168//       {
169//         "key": "payee",
170//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
171//       },
172//       {
173//         "key": "session",
174//         "value": "g1psdsf789f4xw3qrpjue54g2h28syd09yfkrxdh"
175//       },
176//       {
177//         "key": "expires",
178//         "value": "1234567950"
179//       },
180//       {
181//         "key": "first",
182//         "value": "1234567890"
183//       },
184//       {
185//         "key": "carried",
186//         "value": "0"
187//       }
188//     ],
189//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
190//   },
191//   {
192//     "type": "MandatePruned",
193//     "attrs": [
194//       {
195//         "key": "mandate",
196//         "value": "2"
197//       },
198//       {
199//         "key": "plan",
200//         "value": "1"
201//       },
202//       {
203//         "key": "payer",
204//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
205//       },
206//       {
207//         "key": "kept",
208//         "value": "0"
209//       }
210//     ],
211//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
212//   },
213//   {
214//     "type": "Subscribed",
215//     "attrs": [
216//       {
217//         "key": "mandate",
218//         "value": "3"
219//       },
220//       {
221//         "key": "plan",
222//         "value": "1"
223//       },
224//       {
225//         "key": "payer",
226//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
227//       },
228//       {
229//         "key": "payee",
230//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
231//       },
232//       {
233//         "key": "session",
234//         "value": "g1psdsf789f4xw3qrpjue54g2h28syd09yfkrxdh"
235//       },
236//       {
237//         "key": "expires",
238//         "value": "1234654355"
239//       },
240//       {
241//         "key": "first",
242//         "value": "1234567955"
243//       },
244//       {
245//         "key": "carried",
246//         "value": "0"
247//       }
248//     ],
249//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate"
250//   }
251// ]