mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 12:44:19 +01:00
New boarding protocol (#279)
* [domain] add reverse boarding inputs in Payment struct * [tx-builder] support reverse boarding script * [wallet] add GetTransaction * [api-spec][application] add reverse boarding support in covenantless * [config] add reverse boarding config * [api-spec] add ReverseBoardingAddress RPC * [domain][application] support empty forfeits txs in EndFinalization events * [tx-builder] optional connector output in round tx * [btc-embedded] fix getTx and taproot finalizer * whitelist ReverseBoardingAddress RPC * [test] add reverse boarding integration test * [client] support reverse boarding * [sdk] support reverse boarding * [e2e] add sleep time after faucet * [test] run using bitcoin-core RPC * [tx-builder] fix GetSweepInput * [application][tx-builder] support reverse onboarding in covenant * [cli] support reverse onboarding in covenant CLI * [test] rework integration tests * [sdk] remove onchain wallet, replace by onboarding address * remove old onboarding protocols * [sdk] Fix RegisterPayment * [e2e] add more funds to covenant ASP * [e2e] add sleeping time * several fixes * descriptor boarding * remove boarding delay from info * [sdk] implement descriptor boarding * go mod tidy * fixes and revert error msgs * move descriptor pkg to common * add replace in go.mod * [sdk] fix unit tests * rename DescriptorInput --> BoardingInput * genrest in SDK * remove boarding input from domain * remove all "reverse boarding" * rename "onboarding" ==> "boarding" * remove outdate payment unit test * use tmpfs docker volument for compose testing files * several fixes
This commit is contained in:
350
common/descriptor/parser_test.go
Normal file
350
common/descriptor/parser_test.go
Normal file
@@ -0,0 +1,350 @@
|
||||
package descriptor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ark-network/ark/common/descriptor"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseTaprootDescriptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
desc string
|
||||
expected descriptor.TaprootDescriptor
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Basic Taproot",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,{pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c)})",
|
||||
expected: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"},
|
||||
ScriptTree: []descriptor.Expression{
|
||||
&descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "VTXO",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,{pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c),and(pk(59bffef74a89f39715b9f6b8a83e53a60a458d45542f20e2e2f4f7dbffafc5f8),older(144))})",
|
||||
expected: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"},
|
||||
ScriptTree: []descriptor.Expression{
|
||||
&descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
&descriptor.And{
|
||||
First: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "59bffef74a89f39715b9f6b8a83e53a60a458d45542f20e2e2f4f7dbffafc5f8",
|
||||
},
|
||||
},
|
||||
},
|
||||
Second: &descriptor.Older{
|
||||
Timeout: 144,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Boarding",
|
||||
desc: "tr(0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0,{ and(pk(873079a0091c9b16abd1f8c508320b07f0d50144d09ccd792ce9c915dac60465), pk(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)), and(older(604672), pk(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)) })",
|
||||
expected: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"},
|
||||
ScriptTree: []descriptor.Expression{
|
||||
&descriptor.And{
|
||||
First: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "873079a0091c9b16abd1f8c508320b07f0d50144d09ccd792ce9c915dac60465",
|
||||
},
|
||||
},
|
||||
},
|
||||
Second: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&descriptor.And{
|
||||
Second: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
||||
},
|
||||
},
|
||||
},
|
||||
First: &descriptor.Older{
|
||||
Timeout: 604672,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Invalid Key",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798G,{pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c)})",
|
||||
expected: descriptor.TaprootDescriptor{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Invalid Descriptor Format",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)",
|
||||
expected: descriptor.TaprootDescriptor{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Invalid Descriptor Format - Missing Script Tree",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)",
|
||||
expected: descriptor.TaprootDescriptor{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Valid Empty Script Tree",
|
||||
desc: "tr(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,{})",
|
||||
expected: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"},
|
||||
ScriptTree: []descriptor.Expression{},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := descriptor.ParseTaprootDescriptor(tt.desc)
|
||||
if (err != nil) != tt.wantErr {
|
||||
require.Equal(t, tt.wantErr, err != nil, err)
|
||||
return
|
||||
}
|
||||
require.Equal(t, tt.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompileDescriptor(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
desc descriptor.TaprootDescriptor
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "Basic Taproot",
|
||||
desc: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: descriptor.UnspendableKey},
|
||||
ScriptTree: []descriptor.Expression{
|
||||
&descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: "tr(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,{pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c)})",
|
||||
},
|
||||
{
|
||||
name: "VTXO",
|
||||
desc: descriptor.TaprootDescriptor{
|
||||
InternalKey: descriptor.Key{Hex: descriptor.UnspendableKey},
|
||||
ScriptTree: []descriptor.Expression{
|
||||
&descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
&descriptor.And{
|
||||
First: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "59bffef74a89f39715b9f6b8a83e53a60a458d45542f20e2e2f4f7dbffafc5f8",
|
||||
},
|
||||
},
|
||||
},
|
||||
Second: &descriptor.Older{
|
||||
Timeout: 1024,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: "tr(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,{pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c),and(pk(59bffef74a89f39715b9f6b8a83e53a60a458d45542f20e2e2f4f7dbffafc5f8),older(1024))})",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := descriptor.CompileDescriptor(tt.desc)
|
||||
require.Equal(t, tt.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePk(t *testing.T) {
|
||||
tests := []struct {
|
||||
policy string
|
||||
expectedScript string
|
||||
expected descriptor.PK
|
||||
verify bool
|
||||
}{
|
||||
{
|
||||
policy: "pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c)",
|
||||
expectedScript: "2081e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952cac",
|
||||
verify: false,
|
||||
expected: descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
policy: "pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c)",
|
||||
expectedScript: "2081e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952cad",
|
||||
verify: true,
|
||||
expected: descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
var parsed descriptor.PK
|
||||
err := parsed.Parse(test.policy)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expected, parsed)
|
||||
|
||||
script, err := parsed.Script(test.verify)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expectedScript, script)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOlder(t *testing.T) {
|
||||
tests := []struct {
|
||||
policy string
|
||||
expectedScript string
|
||||
expected descriptor.Older
|
||||
}{
|
||||
{
|
||||
policy: "older(512)",
|
||||
expectedScript: "03010040b275",
|
||||
expected: descriptor.Older{
|
||||
Timeout: uint(512),
|
||||
},
|
||||
},
|
||||
{
|
||||
policy: "older(1024)",
|
||||
expectedScript: "03020040b275",
|
||||
expected: descriptor.Older{
|
||||
Timeout: uint(1024),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
var parsed descriptor.Older
|
||||
err := parsed.Parse(test.policy)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expected, parsed)
|
||||
|
||||
script, err := parsed.Script(false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expectedScript, script)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAnd(t *testing.T) {
|
||||
tests := []struct {
|
||||
policy string
|
||||
expectedScript string
|
||||
expected descriptor.And
|
||||
}{
|
||||
{
|
||||
policy: "and(pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c), older(512))",
|
||||
expectedScript: "2081e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952cad03010040b275",
|
||||
expected: descriptor.And{
|
||||
First: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
Second: &descriptor.Older{
|
||||
Timeout: 512,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
policy: "and(older(512), pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c))",
|
||||
expectedScript: "03010040b2752081e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952cac",
|
||||
expected: descriptor.And{
|
||||
Second: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
First: &descriptor.Older{
|
||||
Timeout: 512,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
policy: "and(pk(81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c), pk(79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798))",
|
||||
expectedScript: "2081e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952cad2079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac",
|
||||
expected: descriptor.And{
|
||||
First: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "81e0351fc94c3ba05f8d68354ff44711b02223f2b32fb7f3ef3a99a90af7952c",
|
||||
},
|
||||
},
|
||||
},
|
||||
Second: &descriptor.PK{
|
||||
Key: descriptor.XOnlyKey{
|
||||
descriptor.Key{
|
||||
Hex: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
var parsed descriptor.And
|
||||
err := parsed.Parse(test.policy)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expected, parsed)
|
||||
|
||||
script, err := parsed.Script(false)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expectedScript, script)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user