Skip to content

Commit 5a9239d

Browse files
committed
itest: add custom oracle address harness option
Not all itests need to use an oracle server harness, so we introduce a functional option that may be defined when setting up a harness. This will reduce the overall diff as previous callers of the harness setup functions won't need to change their arguments.
1 parent 86adb91 commit 5a9239d

File tree

3 files changed

+116
-11
lines changed

3 files changed

+116
-11
lines changed

itest/rfq_test.go

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,69 @@ type rfqTestScenario struct {
546546
CarolTapd *tapdHarness
547547
}
548548

549+
// rfqTestScenarioOpts is a struct that holds options related to creating an rfq
550+
// test scenario.
551+
type rfqTestScenarioOpts struct {
552+
oracleServerAddr string
553+
oracleServerAlice string
554+
oracleServerBob string
555+
oracleServerCarol string
556+
}
557+
558+
// RfqOption is a functional option that edits an existing instance of rfq
559+
// test scenario options.
560+
type RfqOption func(*rfqTestScenarioOpts)
561+
562+
// DefaultRfqOptions returns the default set of rfq test scenario options.
563+
func DefaultRfqOptions() rfqTestScenarioOpts {
564+
return rfqTestScenarioOpts{}
565+
}
566+
567+
// WithRfqOracleServer is a functional option that sets the oracle server option
568+
// to the provided string. This oracle server will be the default oracle for
569+
// all test scenario tapd nodes.
570+
func WithRfqOracleServer(s string) RfqOption {
571+
return func(rtso *rfqTestScenarioOpts) {
572+
rtso.oracleServerAddr = s
573+
}
574+
}
575+
576+
// WithAliceOracleServer sets the oracle server to be used by Alice tapd. This
577+
// will override the global oracle server option.
578+
func WithAliceOracleServer(s string) RfqOption {
579+
return func(rtso *rfqTestScenarioOpts) {
580+
rtso.oracleServerAlice = s
581+
}
582+
}
583+
584+
// WithBobOracleServer sets the oracle server to be used by Bob tapd. This will
585+
// override the global oracle server option.
586+
func WithBobOracleServer(s string) RfqOption {
587+
return func(rtso *rfqTestScenarioOpts) {
588+
rtso.oracleServerBob = s
589+
}
590+
}
591+
592+
// WithCarolOracleServer sets the oracle server to be used by Carol tapd. This
593+
// will override the global oracle server option.
594+
func WithCarolOracleServer(s string) RfqOption {
595+
return func(rtso *rfqTestScenarioOpts) {
596+
rtso.oracleServerCarol = s
597+
}
598+
}
599+
549600
// newRfqTestScenario initializes a new test scenario with three new LND nodes
550601
// and connects them to have the following topology,
551602
//
552603
// Alice --> Bob --> Carol
553604
//
554605
// It also creates new tapd nodes for each of the LND nodes.
555-
func newRfqTestScenario(t *harnessTest) *rfqTestScenario {
606+
func newRfqTestScenario(t *harnessTest, opts ...RfqOption) *rfqTestScenario {
607+
rfqOpts := DefaultRfqOptions()
608+
for _, opt := range opts {
609+
opt(&rfqOpts)
610+
}
611+
556612
// Specify wallet outputs to fund the wallets of the new nodes.
557613
const fundAmount = 1 * btcutil.SatoshiPerBitcoin
558614

@@ -607,9 +663,22 @@ func newRfqTestScenario(t *harnessTest) *rfqTestScenario {
607663
t.lndHarness.AssertTopologyChannelOpen(carolLnd, aliceBobChannel)
608664

609665
// Create tapd nodes.
610-
aliceTapd := setupTapdHarness(t.t, t, aliceLnd, t.universeServer)
611-
bobTapd := setupTapdHarness(t.t, t, bobLnd, t.universeServer)
612-
carolTapd := setupTapdHarness(t.t, t, carolLnd, t.universeServer)
666+
aliceTapd := setupTapdHarness(
667+
t.t, t, aliceLnd, t.universeServer, WithOracleServer(
668+
rfqOpts.oracleServerAddr, rfqOpts.oracleServerAlice,
669+
),
670+
)
671+
672+
bobTapd := setupTapdHarness(
673+
t.t, t, bobLnd, t.universeServer, WithOracleServer(
674+
rfqOpts.oracleServerAddr, rfqOpts.oracleServerBob,
675+
),
676+
)
677+
carolTapd := setupTapdHarness(
678+
t.t, t, carolLnd, t.universeServer, WithOracleServer(
679+
rfqOpts.oracleServerAddr, rfqOpts.oracleServerCarol,
680+
),
681+
)
613682

614683
ts := rfqTestScenario{
615684
testHarness: t,

itest/tapd_harness.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type harnessOpts struct {
118118
proofCourier proof.CourierHarness
119119
custodianProofRetrievalDelay *time.Duration
120120
addrAssetSyncerDisable bool
121+
oracleServerAddress string
121122

122123
// fedSyncTickerInterval is the interval at which the federation envoy
123124
// sync ticker will fire.
@@ -138,6 +139,14 @@ func defaultHarnessOpts() *harnessOpts {
138139
return &harnessOpts{}
139140
}
140141

142+
// withOracleAddress is a functional option that sets the oracle address option
143+
// to the provided string.
144+
func withOracleAddress(addr string) harnessOption {
145+
return func(ho *harnessOpts) {
146+
ho.oracleServerAddress = addr
147+
}
148+
}
149+
141150
// newTapdHarness creates a new tapd server harness with the given
142151
// configuration.
143152
func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
@@ -218,13 +227,20 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
218227
// was not set, this will be false, which is the default.
219228
tapCfg.AddrBook.DisableSyncer = opts.addrAssetSyncerDisable
220229

221-
// Set the experimental config for the RFQ service.
222-
tapCfg.Experimental = &tapcfg.ExperimentalConfig{
223-
Rfq: rfq.CliConfig{
224-
//nolint:lll
225-
PriceOracleAddress: rfq.MockPriceOracleServiceAddress,
226-
MockOracleAssetsPerBTC: 5_820_600,
227-
},
230+
switch {
231+
case len(opts.oracleServerAddress) > 0:
232+
tapCfg.Experimental.Rfq.PriceOracleAddress =
233+
opts.oracleServerAddress
234+
235+
default:
236+
// Set the experimental config for the RFQ service.
237+
tapCfg.Experimental = &tapcfg.ExperimentalConfig{
238+
Rfq: rfq.CliConfig{
239+
//nolint:lll
240+
PriceOracleAddress: rfq.MockPriceOracleServiceAddress,
241+
MockOracleAssetsPerBTC: 5_820_600,
242+
},
243+
}
228244
}
229245

230246
cfgLogger := tapCfg.LogWriter.GenSubLogger("CONF", nil)

itest/test_harness.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,29 @@ type tapdHarnessParams struct {
386386

387387
// disableSyncCache indicates whether the sync cache should be disabled.
388388
disableSyncCache bool
389+
390+
// oracleServerAddress defines the oracle server's address that this
391+
// tapd harness is going to use.
392+
oracleServerAddress string
389393
}
390394

395+
// Option is a tapd harness option.
391396
type Option func(*tapdHarnessParams)
392397

398+
// WithOracleServer is a functional option that sets the oracle server address
399+
// option to the provided string.
400+
func WithOracleServer(global, override string) Option {
401+
return func(th *tapdHarnessParams) {
402+
switch {
403+
case len(override) > 0:
404+
th.oracleServerAddress = override
405+
406+
case len(global) > 0:
407+
th.oracleServerAddress = global
408+
}
409+
}
410+
}
411+
393412
// setupTapdHarness creates a new tapd that connects to the given lnd node
394413
// and to the given universe server.
395414
func setupTapdHarness(t *testing.T, ht *harnessTest,
@@ -422,6 +441,7 @@ func setupTapdHarness(t *testing.T, ht *harnessTest,
422441
ho.fedSyncTickerInterval = params.fedSyncTickerInterval
423442
ho.sqliteDatabaseFilePath = params.sqliteDatabaseFilePath
424443
ho.disableSyncCache = params.disableSyncCache
444+
ho.oracleServerAddress = params.oracleServerAddress
425445
}
426446

427447
tapdCfg := tapdConfig{

0 commit comments

Comments
 (0)