render_example_test.gno
3.18 Kb · 97 lines
1package merkledrop
2
3// ExampleRender pins the realm's Render output as a testable example.
4func ExampleRender() {
5 seed()
6 print(Render(""))
7 // Output:
8 // # MerkleDrop v1
9 //
10 // A Merkle root gates an airdrop that pays real ugnot. Successor to
11 // [v0](/r/moul/x/daily/merkledrop/v0), which moved no coins and whose proof scheme was
12 // safe only by accident of encoding lengths.
13 //
14 // ## Drop
15 //
16 // | Field | Value |
17 // |---|---|
18 // | Root | `6964baa99da23b9d8c76774c6f1122b250040e29c1d75823dda15c043dc65755` |
19 // | Allocations | 4 |
20 // | Closes at height | never |
21 // | Claimed | 0 |
22 // | Paid out | 0 ugnot |
23 // | Funding address | `g1jvh5ukk07dvd57fxefcp5aa29xaydxmxs7myyp` |
24 //
25 // ## How it differs from v0
26 //
27 // 1. **Domain separated leaves.** v0 hashed leaves bare and combined nodes
28 // commutatively, so an inner-node hash was also a valid leaf hash. It was not
29 // exploitable, but only because a v0 leaf preimage tops out at 61 bytes while an
30 // inner preimage is always 64. v1 tags leaves `0x00` and inner nodes `0x01`.
31 // 2. **Proofs bound to a position.** v0 folded a sibling list of any length. v1
32 // carries index and total, rebuilds the tree shape, and caps the depth.
33 // 3. **A settable root and a closing height.** v0's root was a `const`.
34 // 4. **Real coins.** v0 kept a `uint64` ledger and moved nothing.
35 //
36 // ## Leaf encoding
37 //
38 // Reproduce this off chain to rebuild the tree:
39 //
40 // ```
41 // leaf = "gno.land/r/moul/x/daily/merkledrop/v1|<index>|<address>|<amount>"
42 // tree = Tendermint simple tree, leaf 0x00, inner 0x01
43 // ```
44 //
45 // ## Example allocations
46 //
47 // Seeded at deploy so the drop can be exercised without a generator. A live drop
48 // commits only a root and stores none of this.
49 //
50 // | # | Address | Amount | Claimed |
51 // |---|---|---|---|
52 // | [0](/r/moul/x/daily/merkledrop/v1:proof/0) | `g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5` | 100 | no |
53 // | [1](/r/moul/x/daily/merkledrop/v1:proof/1) | `g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj` | 250 | no |
54 // | [2](/r/moul/x/daily/merkledrop/v1:proof/2) | `g1manfred47kzduec920z88wfr64ylksmdcedlf5` | 500 | no |
55 // | [3](/r/moul/x/daily/merkledrop/v1:proof/3) | `g1sss9uxef4l6lwc0mxq8n5v0e4vqpml7c39cxq2` | 750 | no |
56}
57
58// ExampleRenderProof pins one allocation page, including its live proof.
59func ExampleRenderProof() {
60 seed()
61 print(Render("proof/2"))
62 // Output:
63 // # MerkleDrop v1: allocation 2
64 //
65 // | Field | Value |
66 // |---|---|
67 // | Index | 2 |
68 // | Total | 4 |
69 // | Address | `g1manfred47kzduec920z88wfr64ylksmdcedlf5` |
70 // | Amount | 500 ugnot |
71 // | Claimed | no |
72 //
73 // ## Leaf
74 //
75 // ```
76 // gno.land/r/moul/x/daily/merkledrop/v1|2|g1manfred47kzduec920z88wfr64ylksmdcedlf5|500
77 // ```
78 //
79 // ## Proof
80 //
81 // ```
82 // 337bb23c66f621db38e704fc2d64d27d5fa6308a333fd9d2d69c6ccd9390c056,b498260d909eee2a1b8a88524d5e4d08128aa7d8ca433468379db031976958e1
83 // ```
84 //
85 // Only `g1manfred47kzduec920z88wfr64ylksmdcedlf5` can spend it: the address is inside the leaf, so
86 // the proof verifies for no one else.
87}
88
89// ExampleRenderMissingProof pins the not-found page.
90func ExampleRenderMissingProof() {
91 seed()
92 print(Render("proof/99"))
93 // Output:
94 // # MerkleDrop v1
95 //
96 // No allocation `99`.
97}