New address encoding (#356)

* [common] rework address encoding

* new address encoding

* replace offchain address by vtxo output key in DB

* merge migrations files into init one

* fix txbuilder fixtures

* fix transaction events
This commit is contained in:
Louis Singer
2024-10-18 16:50:07 +02:00
committed by GitHub
parent b1c9261f14
commit b536a9e652
58 changed files with 2243 additions and 1896 deletions

View File

@@ -4,14 +4,12 @@ import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"os"
"reflect"
"sort"
"testing"
"time"
"github.com/ark-network/ark/common/descriptor"
"github.com/ark-network/ark/common/tree"
"github.com/ark-network/ark/server/internal/core/domain"
"github.com/ark-network/ark/server/internal/core/ports"
@@ -24,26 +22,8 @@ import (
const (
emptyPtx = "cHNldP8BAgQCAAAAAQQBAAEFAQABBgEDAfsEAgAAAAA="
emptyTx = "0200000000000000000000"
pubkey1 = "00000000000000000000000000000000000000000000000000000000000000001"
pubkey2 = "00000000000000000000000000000000000000000000000000000000000000002"
)
var desc1 = fmt.Sprintf(
descriptor.DefaultVtxoDescriptorTemplate,
randomString(66),
pubkey1,
pubkey1,
512,
pubkey1,
)
var desc2 = fmt.Sprintf(
descriptor.DefaultVtxoDescriptorTemplate,
randomString(66),
pubkey2,
pubkey2,
512,
pubkey2,
pubkey = "25a43cecfa0e1b1a4f72d64ad15f4cfa7a84d0723e8511c969aa543638ea9967"
pubkey2 = "33ffb3dee353b1a9ebe4ced64b946238d0a4ac364f275d771da6ad2445d07ae0"
)
var congestionTree = [][]tree.Node{
@@ -270,15 +250,13 @@ func testRoundRepository(t *testing.T, svc ports.RepoManager) {
},
RoundTxid: randomString(32),
ExpireAt: 7980322,
Receiver: domain.Receiver{
Descriptor: randomString(120),
Amount: 300,
},
Pubkey: randomString(32),
Amount: 300,
},
},
Receivers: []domain.Receiver{{
Descriptor: randomString(120),
Amount: 300,
Pubkey: randomString(32),
Amount: 300,
}},
},
{
@@ -292,20 +270,18 @@ func testRoundRepository(t *testing.T, svc ports.RepoManager) {
},
RoundTxid: randomString(32),
ExpireAt: 7980322,
Receiver: domain.Receiver{
Descriptor: randomString(120),
Amount: 600,
},
Pubkey: randomString(32),
Amount: 600,
},
},
Receivers: []domain.Receiver{
{
Descriptor: randomString(120),
Amount: 400,
Pubkey: randomString(32),
Amount: 400,
},
{
Descriptor: randomString(120),
Amount: 200,
Pubkey: randomString(32),
Amount: 200,
},
},
},
@@ -370,20 +346,16 @@ func testVtxoRepository(t *testing.T, svc ports.RepoManager) {
Txid: randomString(32),
VOut: 0,
},
Receiver: domain.Receiver{
Descriptor: desc1,
Amount: 1000,
},
Pubkey: pubkey,
Amount: 1000,
},
{
VtxoKey: domain.VtxoKey{
Txid: randomString(32),
VOut: 1,
},
Receiver: domain.Receiver{
Descriptor: desc1,
Amount: 2000,
},
Pubkey: pubkey,
Amount: 2000,
},
}
newVtxos := append(userVtxos, domain.Vtxo{
@@ -391,10 +363,8 @@ func testVtxoRepository(t *testing.T, svc ports.RepoManager) {
Txid: randomString(32),
VOut: 1,
},
Receiver: domain.Receiver{
Descriptor: desc2,
Amount: 2000,
},
Pubkey: pubkey2,
Amount: 2000,
})
vtxoKeys := make([]domain.VtxoKey, 0, len(userVtxos))
@@ -406,7 +376,7 @@ func testVtxoRepository(t *testing.T, svc ports.RepoManager) {
require.Error(t, err)
require.Empty(t, vtxos)
spendableVtxos, spentVtxos, err := svc.Vtxos().GetAllVtxos(ctx, pubkey1)
spendableVtxos, spentVtxos, err := svc.Vtxos().GetAllVtxos(ctx, pubkey)
require.NoError(t, err)
require.Empty(t, spendableVtxos)
require.Empty(t, spentVtxos)
@@ -423,7 +393,7 @@ func testVtxoRepository(t *testing.T, svc ports.RepoManager) {
require.NoError(t, err)
require.Exactly(t, userVtxos, vtxos)
spendableVtxos, spentVtxos, err = svc.Vtxos().GetAllVtxos(ctx, pubkey1)
spendableVtxos, spentVtxos, err = svc.Vtxos().GetAllVtxos(ctx, pubkey)
require.NoError(t, err)
sortedVtxos := sortVtxos(userVtxos)
@@ -449,7 +419,7 @@ func testVtxoRepository(t *testing.T, svc ports.RepoManager) {
require.True(t, v.Spent)
}
spendableVtxos, spentVtxos, err = svc.Vtxos().GetAllVtxos(ctx, pubkey1)
spendableVtxos, spentVtxos, err = svc.Vtxos().GetAllVtxos(ctx, pubkey)
require.NoError(t, err)
require.Exactly(t, vtxos[1:], spendableVtxos)
require.Len(t, spentVtxos, len(vtxoKeys[:1]))