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",
72 "53797b879169765379a00087641c00000052795279a0696321000000765279a069",
75 "TestIfAndMultiClause",
76 equitytest.TestIfAndMultiClause,
77 "7b641f0000007087916976547aa00087641a000000765379a06963240000007b7bae7cac",
81 equitytest.TestIfNesting,
82 "7b644400000054795279879169765579a00087643500000052795479a000876429000000765379a06952795579879169633a000000765479a06953797b8791635c0000007654798791695279a000876459000000527978a0697d8791",
85 for _, c := range cases {
86 t.Run(c.name, func(t *testing.T) {
87 r := strings.NewReader(c.contract)
88 compiled, err := Compile(r)
93 contract := compiled[len(compiled)-1]
94 got := []byte(contract.Body)
96 want, err := hex.DecodeString(c.want)
101 if string(got) != string(want) {
102 t.Errorf("%s got %s\nwant %s", c.name, hex.EncodeToString(got), hex.EncodeToString(want))
108 func mustDecodeHex(h string) *chainjson.HexBytes {
109 bits, err := hex.DecodeString(h)
113 result := chainjson.HexBytes(bits)