8 chainjson "github.com/bytom/encoding/json"
10 "github.com/equity/compiler/equitytest"
13 func TestCompile(t *testing.T) {
21 equitytest.TrivialLock,
26 equitytest.LockWithPublicKey,
30 "LockWithPublicKeyHash",
31 equitytest.LockWithPKHash,
36 equitytest.LockWith2of3Keys,
37 "537a547a526bae71557a536c7cad",
41 equitytest.LockToOutput,
46 equitytest.TradeOffer,
47 "547a6413000000007b7b51547ac1631a000000547a547aae7cac",
51 equitytest.EscrowedTransfer,
52 "537a641a000000537a7cae7cac6900c3c251557ac16328000000537a7cae7cac6900c3c251547ac1",
56 equitytest.RevealPreimage,
61 equitytest.PriceChanger,
62 "557a6432000000557a5479ae7cac6900c3c25100597a89587a89587a89587a89557a890274787e008901c07ec1633a000000007b537a51567ac1",
66 equitytest.TestDefineVar,
67 "52797b937b7887916987",
71 equitytest.TestAssignVar,
77 "53797b879169765379a00087641c00000052795279a0696321000000765279a069",
80 "TestIfAndMultiClause",
81 equitytest.TestIfAndMultiClause,
82 "7b641f0000007087916976547aa00087641a000000765379a06963240000007b7bae7cac",
86 equitytest.TestIfNesting,
87 "7b644400000054795279879169765579a00087643500000052795479a000876429000000765379a06952795579879169633a000000765479a06953797b8791635c0000007654798791695279a000876459000000527978a0697d8791",
91 equitytest.TestConstantMath,
92 "547a547a935a93880431323330aa8806737472696e67aa87",
95 for _, c := range cases {
96 t.Run(c.name, func(t *testing.T) {
97 r := strings.NewReader(c.contract)
98 compiled, err := Compile(r)
103 contract := compiled[len(compiled)-1]
104 got := []byte(contract.Body)
106 want, err := hex.DecodeString(c.want)
111 if string(got) != string(want) {
112 t.Errorf("%s got %s\nwant %s", c.name, hex.EncodeToString(got), hex.EncodeToString(want))
118 func mustDecodeHex(h string) *chainjson.HexBytes {
119 bits, err := hex.DecodeString(h)
123 result := chainjson.HexBytes(bits)