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

11.67 Kb · 457 lines
  1// PKGPATH: gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster/filetests/z_events_filetest
  2
  3// Every state change emits one event with the quest id, the acting address
  4// and, where money moves, the amount and recipient.
  5package z_events_filetest
  6
  7import (
  8	"chain"
  9	"testing"
 10
 11	"gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
 12)
 13
 14const (
 15	poster  = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
 16	builder = address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // test2
 17	other   = address("g1rzuwh5frve732k4futyw45y78rzuty4626zy6h") // test3
 18)
 19
 20func post(cur realm, reward int64) uint64 {
 21	testing.SetRealm(testing.NewUserRealm(poster))
 22	testing.SetOriginSend(chain.Coins{{Denom: "ugnot", Amount: reward}})
 23	testing.IssueCoins(chain.PackageAddress("gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"), chain.Coins{{Denom: "ugnot", Amount: reward}})
 24	id := questmaster.PostQuest(cross(cur), "Event quest", "", 1000)
 25	testing.SetOriginSend(nil)
 26	return id
 27}
 28
 29func main(cur realm) {
 30	// quest 1: claim, unclaim, claim, release, claim, submit, reject, claim, submit, approve
 31	id := post(cur, 2_000_000)
 32	testing.SetRealm(testing.NewUserRealm(builder))
 33	questmaster.ClaimQuest(cross(cur), id)
 34	questmaster.UnclaimQuest(cross(cur), id)
 35	questmaster.ClaimQuest(cross(cur), id)
 36	testing.SkipHeights(1001)
 37	testing.SetRealm(testing.NewUserRealm(other))
 38	questmaster.ReleaseQuest(cross(cur), id)
 39	testing.SetRealm(testing.NewUserRealm(builder))
 40	questmaster.ClaimQuest(cross(cur), id)
 41	questmaster.SubmitWork(cross(cur), id, "https://example.com/1")
 42	testing.SetRealm(testing.NewUserRealm(poster))
 43	questmaster.RejectWork(cross(cur), id, "needs tests")
 44	testing.SetRealm(testing.NewUserRealm(builder))
 45	questmaster.ClaimQuest(cross(cur), id)
 46	questmaster.SubmitWork(cross(cur), id, "https://example.com/2")
 47	testing.SetRealm(testing.NewUserRealm(poster))
 48	questmaster.ApproveWork(cross(cur), id)
 49
 50	// quest 2: cancel with refund
 51	id2 := post(cur, 1_000_000)
 52	testing.SetRealm(testing.NewUserRealm(poster))
 53	questmaster.CancelQuest(cross(cur), id2)
 54
 55	// quest 3: payout after the review window
 56	id3 := post(cur, 3_000_000)
 57	testing.SetRealm(testing.NewUserRealm(builder))
 58	questmaster.ClaimQuest(cross(cur), id3)
 59	questmaster.SubmitWork(cross(cur), id3, "https://example.com/3")
 60	testing.SkipHeights(172_801)
 61	questmaster.ClaimPayout(cross(cur), id3)
 62
 63	// quest 4: claimed, closed by the poster, unclaimed -> refund
 64	id4 := post(cur, 4_000_000)
 65	testing.SetRealm(testing.NewUserRealm(builder))
 66	questmaster.ClaimQuest(cross(cur), id4)
 67	testing.SetRealm(testing.NewUserRealm(poster))
 68	questmaster.CancelQuest(cross(cur), id4)
 69	testing.SetRealm(testing.NewUserRealm(builder))
 70	questmaster.UnclaimQuest(cross(cur), id4)
 71
 72	t := questmaster.GetTotals()
 73	println(t.Posted, t.Locked, t.Paid, t.Refunded)
 74}
 75
 76// Output:
 77// 10000000 0 5000000 5000000
 78
 79// Events:
 80// [
 81//   {
 82//     "type": "QuestPosted",
 83//     "attrs": [
 84//       {
 85//         "key": "id",
 86//         "value": "1"
 87//       },
 88//       {
 89//         "key": "actor",
 90//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
 91//       },
 92//       {
 93//         "key": "amount",
 94//         "value": "2000000"
 95//       }
 96//     ],
 97//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
 98//   },
 99//   {
100//     "type": "QuestClaimed",
101//     "attrs": [
102//       {
103//         "key": "id",
104//         "value": "1"
105//       },
106//       {
107//         "key": "actor",
108//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
109//       }
110//     ],
111//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
112//   },
113//   {
114//     "type": "QuestUnclaimed",
115//     "attrs": [
116//       {
117//         "key": "id",
118//         "value": "1"
119//       },
120//       {
121//         "key": "actor",
122//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
123//       }
124//     ],
125//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
126//   },
127//   {
128//     "type": "QuestClaimed",
129//     "attrs": [
130//       {
131//         "key": "id",
132//         "value": "1"
133//       },
134//       {
135//         "key": "actor",
136//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
137//       }
138//     ],
139//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
140//   },
141//   {
142//     "type": "QuestReleased",
143//     "attrs": [
144//       {
145//         "key": "id",
146//         "value": "1"
147//       },
148//       {
149//         "key": "actor",
150//         "value": "g1rzuwh5frve732k4futyw45y78rzuty4626zy6h"
151//       }
152//     ],
153//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
154//   },
155//   {
156//     "type": "QuestClaimed",
157//     "attrs": [
158//       {
159//         "key": "id",
160//         "value": "1"
161//       },
162//       {
163//         "key": "actor",
164//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
165//       }
166//     ],
167//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
168//   },
169//   {
170//     "type": "WorkSubmitted",
171//     "attrs": [
172//       {
173//         "key": "id",
174//         "value": "1"
175//       },
176//       {
177//         "key": "actor",
178//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
179//       }
180//     ],
181//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
182//   },
183//   {
184//     "type": "WorkRejected",
185//     "attrs": [
186//       {
187//         "key": "id",
188//         "value": "1"
189//       },
190//       {
191//         "key": "actor",
192//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
193//       },
194//       {
195//         "key": "builder",
196//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
197//       }
198//     ],
199//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
200//   },
201//   {
202//     "type": "QuestClaimed",
203//     "attrs": [
204//       {
205//         "key": "id",
206//         "value": "1"
207//       },
208//       {
209//         "key": "actor",
210//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
211//       }
212//     ],
213//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
214//   },
215//   {
216//     "type": "WorkSubmitted",
217//     "attrs": [
218//       {
219//         "key": "id",
220//         "value": "1"
221//       },
222//       {
223//         "key": "actor",
224//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
225//       }
226//     ],
227//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
228//   },
229//   {
230//     "type": "QuestPaid",
231//     "attrs": [
232//       {
233//         "key": "id",
234//         "value": "1"
235//       },
236//       {
237//         "key": "actor",
238//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
239//       },
240//       {
241//         "key": "to",
242//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
243//       },
244//       {
245//         "key": "amount",
246//         "value": "2000000"
247//       },
248//       {
249//         "key": "how",
250//         "value": "approved"
251//       }
252//     ],
253//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
254//   },
255//   {
256//     "type": "QuestPosted",
257//     "attrs": [
258//       {
259//         "key": "id",
260//         "value": "2"
261//       },
262//       {
263//         "key": "actor",
264//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
265//       },
266//       {
267//         "key": "amount",
268//         "value": "1000000"
269//       }
270//     ],
271//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
272//   },
273//   {
274//     "type": "QuestCancelled",
275//     "attrs": [
276//       {
277//         "key": "id",
278//         "value": "2"
279//       },
280//       {
281//         "key": "actor",
282//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
283//       },
284//       {
285//         "key": "to",
286//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
287//       },
288//       {
289//         "key": "amount",
290//         "value": "1000000"
291//       },
292//       {
293//         "key": "how",
294//         "value": "open"
295//       }
296//     ],
297//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
298//   },
299//   {
300//     "type": "QuestPosted",
301//     "attrs": [
302//       {
303//         "key": "id",
304//         "value": "3"
305//       },
306//       {
307//         "key": "actor",
308//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
309//       },
310//       {
311//         "key": "amount",
312//         "value": "3000000"
313//       }
314//     ],
315//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
316//   },
317//   {
318//     "type": "QuestClaimed",
319//     "attrs": [
320//       {
321//         "key": "id",
322//         "value": "3"
323//       },
324//       {
325//         "key": "actor",
326//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
327//       }
328//     ],
329//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
330//   },
331//   {
332//     "type": "WorkSubmitted",
333//     "attrs": [
334//       {
335//         "key": "id",
336//         "value": "3"
337//       },
338//       {
339//         "key": "actor",
340//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
341//       }
342//     ],
343//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
344//   },
345//   {
346//     "type": "QuestPaid",
347//     "attrs": [
348//       {
349//         "key": "id",
350//         "value": "3"
351//       },
352//       {
353//         "key": "actor",
354//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
355//       },
356//       {
357//         "key": "to",
358//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
359//       },
360//       {
361//         "key": "amount",
362//         "value": "3000000"
363//       },
364//       {
365//         "key": "how",
366//         "value": "timeout"
367//       }
368//     ],
369//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
370//   },
371//   {
372//     "type": "QuestPosted",
373//     "attrs": [
374//       {
375//         "key": "id",
376//         "value": "4"
377//       },
378//       {
379//         "key": "actor",
380//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
381//       },
382//       {
383//         "key": "amount",
384//         "value": "4000000"
385//       }
386//     ],
387//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
388//   },
389//   {
390//     "type": "QuestClaimed",
391//     "attrs": [
392//       {
393//         "key": "id",
394//         "value": "4"
395//       },
396//       {
397//         "key": "actor",
398//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
399//       }
400//     ],
401//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
402//   },
403//   {
404//     "type": "QuestClosing",
405//     "attrs": [
406//       {
407//         "key": "id",
408//         "value": "4"
409//       },
410//       {
411//         "key": "actor",
412//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
413//       }
414//     ],
415//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
416//   },
417//   {
418//     "type": "QuestUnclaimed",
419//     "attrs": [
420//       {
421//         "key": "id",
422//         "value": "4"
423//       },
424//       {
425//         "key": "actor",
426//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
427//       }
428//     ],
429//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
430//   },
431//   {
432//     "type": "QuestCancelled",
433//     "attrs": [
434//       {
435//         "key": "id",
436//         "value": "4"
437//       },
438//       {
439//         "key": "actor",
440//         "value": "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj"
441//       },
442//       {
443//         "key": "to",
444//         "value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
445//       },
446//       {
447//         "key": "amount",
448//         "value": "4000000"
449//       },
450//       {
451//         "key": "how",
452//         "value": "unclaimed"
453//       }
454//     ],
455//     "pkg_path": "gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/questmaster"
456//   }
457// ]