-
Notifications
You must be signed in to change notification settings - Fork 651
/
test_utxos.go
45 lines (37 loc) · 1.13 KB
/
test_utxos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import (
"context"
"slices"
"github.com/stretchr/testify/require"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/components/avax"
)
func NewDeterministicChainUTXOs(require *require.Assertions, utxoSets map[ids.ID][]*avax.UTXO) *DeterministicChainUTXOs {
globalUTXOs := NewUTXOs()
for subnetID, utxos := range utxoSets {
for _, utxo := range utxos {
require.NoError(
globalUTXOs.AddUTXO(context.Background(), subnetID, constants.PlatformChainID, utxo),
)
}
}
return &DeterministicChainUTXOs{
ChainUTXOs: NewChainUTXOs(constants.PlatformChainID, globalUTXOs),
}
}
type DeterministicChainUTXOs struct {
ChainUTXOs
}
func (c *DeterministicChainUTXOs) UTXOs(ctx context.Context, sourceChainID ids.ID) ([]*avax.UTXO, error) {
utxos, err := c.ChainUTXOs.UTXOs(ctx, sourceChainID)
if err != nil {
return nil, err
}
slices.SortFunc(utxos, func(a, b *avax.UTXO) int {
return a.Compare(&b.UTXOID)
})
return utxos, nil
}