OSDN Git Service

fix related check to support that if-else statement include lock/unlock statement...
[bytom/equity.git] / compiler / equitytest / equitytest.go
1 package equitytest
2
3 const TrivialLock = `
4 contract TrivialLock() locks amount of asset {
5   clause trivialUnlock() {
6     unlock amount of asset
7   }
8 }
9 `
10
11 const LockWithPublicKey = `
12 contract LockWithPublicKey(publicKey: PublicKey) locks amount of asset {
13   clause unlockWithSig(sig: Signature) {
14     verify checkTxSig(publicKey, sig)
15     unlock amount of asset
16   }
17 }
18 `
19
20 const LockWithPKHash = `
21 contract LockWithPublicKeyHash(pubKeyHash: Hash) locks amount of asset {
22   clause spend(pubKey: PublicKey, sig: Signature) {
23     verify sha3(pubKey) == pubKeyHash
24     verify checkTxSig(pubKey, sig)
25     unlock amount of asset
26   }
27 }
28 `
29
30 const LockWith2of3Keys = `
31 contract LockWith3Keys(pubkey1, pubkey2, pubkey3: PublicKey) locks amount of asset {
32   clause unlockWith2Sigs(sig1, sig2: Signature) {
33     verify checkTxMultiSig([pubkey1, pubkey2, pubkey3], [sig1, sig2])
34     unlock amount of asset
35   }
36 }
37 `
38
39 const LockToOutput = `
40 contract LockToOutput(address: Program) locks amount of asset {
41   clause relock() {
42     lock amount of asset with address
43   }
44 }
45 `
46
47 const TradeOffer = `
48 contract TradeOffer(requestedAsset: Asset, requestedAmount: Amount, sellerProgram: Program, sellerKey: PublicKey) locks amount of asset {
49   clause trade() {
50     lock requestedAmount of requestedAsset with sellerProgram
51     unlock amount of asset
52   }
53   clause cancel(sellerSig: Signature) {
54     verify checkTxSig(sellerKey, sellerSig)
55     unlock amount of asset
56   }
57 }
58 `
59
60 const EscrowedTransfer = `
61 contract EscrowedTransfer(agent: PublicKey, sender: Program, recipient: Program) locks amount of asset {
62   clause approve(sig: Signature) {
63     verify checkTxSig(agent, sig)
64     lock amount of asset with recipient
65   }
66   clause reject(sig: Signature) {
67     verify checkTxSig(agent, sig)
68     lock amount of asset with sender
69   }
70 }
71 `
72
73 const RevealPreimage = `
74 contract RevealPreimage(hash: Hash) locks amount of asset {
75   clause reveal(string: String) {
76     verify sha3(string) == hash
77     unlock amount of asset
78   }
79 }
80 `
81 const PriceChanger = `
82 contract PriceChanger(askAmount: Amount, askAsset: Asset, sellerKey: PublicKey, sellerProg: Program) locks valueAmount of valueAsset {
83   clause changePrice(newAmount: Amount, newAsset: Asset, sig: Signature) {
84     verify checkTxSig(sellerKey, sig)
85     lock valueAmount of valueAsset with PriceChanger(newAmount, newAsset, sellerKey, sellerProg)
86   }
87   clause redeem() {
88     lock askAmount of askAsset with sellerProg
89     unlock valueAmount of valueAsset
90   }
91 }
92 `
93
94 const TestDefineVar = `
95 contract TestDefineVar(result: Integer) locks valueAmount of valueAsset {
96   clause LockWithMath(left: Integer, right: Integer) {
97     define calculate: Integer = left + right
98     verify left != calculate
99     verify result == calculate
100     unlock valueAmount of valueAsset
101   }
102 }
103 `
104
105 const TestSigIf = `
106 contract TestSigIf(a: Integer, count:Integer) locks valueAmount of valueAsset {
107   clause check(b: Integer, c: Integer) {
108     verify b != count
109     if a > b {
110         verify b > c
111     } else {
112         verify a > c
113     }
114     unlock valueAmount of valueAsset
115   }
116 }
117 `
118 const TestIfAndMultiClause = `
119 contract TestIfAndMultiClause(a: Integer, cancelKey: PublicKey) locks valueAmount of valueAsset {
120   clause check(b: Integer, c: Integer) {
121     verify b != c
122     if a > b {
123         verify a > c
124     }
125     unlock valueAmount of valueAsset
126   }
127   clause cancel(sellerSig: Signature) {
128     verify checkTxSig(cancelKey, sellerSig)
129     unlock valueAmount of valueAsset
130   }
131 }
132 `
133
134 const TestIfNesting = `
135 contract TestIfNesting(a: Integer, count:Integer) locks valueAmount of valueAsset {
136   clause check(b: Integer, c: Integer, d: Integer) {
137     verify b != count
138     if a > b {
139         if d > c {
140            verify a > d
141         }
142         verify d != b
143     } else {
144         verify a > c
145     }
146     verify c != count
147     unlock valueAmount of valueAsset
148   }
149   clause cancel(e: Integer, f: Integer) {
150     verify a != e
151     if a > f {
152       verify e > count
153     }
154     verify f != count
155     unlock valueAmount of valueAsset
156   }
157 }
158 `