Skip to content

Commit

Permalink
itest: add price oracly proxy itest
Browse files Browse the repository at this point in the history
  • Loading branch information
sputn1ck committed Feb 18, 2025
1 parent dd8477d commit bee379f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
21 changes: 21 additions & 0 deletions itest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/priceoraclerpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -129,3 +130,23 @@ func testGetInfo(t *harnessTest) {
// Ensure the response matches the expected response.
require.Equal(t.t, resp, respCli)
}

// testPriceOracleProxy tests the price oracle proxy.
func testPriceOracleProxy(t *harnessTest) {
ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
defer cancel()

resp, err := t.tapd.PriceOracleClient.QueryAssetRates(
ctxt, &priceoraclerpc.QueryAssetRatesRequest{},
)
require.NoError(t.t, err)

okResp := resp.GetOk()
require.NotNil(t.t, okResp)

require.Equal(
t.t, fmt.Sprintf("%v", mockPriceOracleCoef),
okResp.AssetRates.SubjectAssetRate.Coefficient,
)
}
9 changes: 8 additions & 1 deletion itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightninglabs/taproot-assets/taprpc/priceoraclerpc"
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
"github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
Expand Down Expand Up @@ -83,6 +84,10 @@ const (
// timeout we'll use for waiting for a receiver to acknowledge a proof
// transfer.
defaultProofTransferReceiverAckTimeout = 500 * time.Millisecond

// mockPriceOracleCoef is the coefficient used in the mock price oracle
// to calculate the asset rate.
mockPriceOracleCoef = 5_820_600
)

// tapdHarness is a test harness that holds everything that is needed to
Expand All @@ -102,6 +107,7 @@ type tapdHarness struct {
tchrpc.TaprootAssetChannelsClient
universerpc.UniverseClient
tapdevrpc.TapDevClient
priceoraclerpc.PriceOracleClient
}

// tapdConfig holds all configuration items that are required to start a tapd
Expand Down Expand Up @@ -223,7 +229,7 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
Rfq: rfq.CliConfig{
//nolint:lll
PriceOracleAddress: rfq.MockPriceOracleServiceAddress,
MockOracleAssetsPerBTC: 5_820_600,
MockOracleAssetsPerBTC: mockPriceOracleCoef,
},
}

Expand Down Expand Up @@ -425,6 +431,7 @@ func (hs *tapdHarness) start(expectErrExit bool) error {
)
hs.UniverseClient = universerpc.NewUniverseClient(rpcConn)
hs.TapDevClient = tapdevrpc.NewTapDevClient(rpcConn)
hs.PriceOracleClient = priceoraclerpc.NewPriceOracleClient(rpcConn)

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions itest/test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ var testCases = []*testCase{
name: "asset signing after lnd restore from seed",
test: testRestoreLndFromSeed,
},
{
name: "price oracle proxy",
test: testPriceOracleProxy,
},
}

var optionalTestCases = []*testCase{
Expand Down

0 comments on commit bee379f

Please sign in to comment.