Skip to content

Commit

Permalink
replace existing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
lalexgap committed Oct 12, 2022
1 parent 2275d89 commit c7c103f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 247 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

func main() {
run.InvokeMap(map[string]interface{}{
"virtual-payment": run.InitializedTestCaseFn(tests.CreateVirtualPaymentTest),
"multi-hop-virtual-payment": run.InitializedTestCaseFn(tests.CreateMultiHopVirtualPaymentTest),
"virtual-payment": run.InitializedTestCaseFn(tests.CreateVirtualPaymentTest),
})
}
18 changes: 1 addition & 17 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,8 @@ isNightly = {type = "bool", default = false, desc = "Whether this test is being
networkJitter = {type = "int", unit = "milliseconds", default = 0}
networkLatency = {type = "int", unit = "milliseconds", default = 0}
numOfHubs = {type = "int", default = 1, desc = "The number of instances that should play the role of the hub"}
numOfIntermediaries = {type = "int", default = 1, desc = "The number of intermediaries(hops) to use in the virtual payment channel"}
numOfPayeePayers = {type = "int", default = 0, desc = "The number of instances that should play the role of the payeepayer"}
numOfPayees = {type = "int", default = 1, desc = "The number of instances that should play the role of the payee"}
numOfPayers = {type = "int", default = 1, desc = "The number of instances that should play the role of the payer"}
paymentTestDuration = {type = "int", default = 10, unit = "seconds"}

[[testcases]]
instances = {min = 2, max = 100, default = 5}
name = "multi-hop-virtual-payment"

[testcases.params]
concurrentPaymentJobs = {type = "int", desc = "The number of concurrent payment jobs a peer should attempt to maintain", default = 1}
isCI = {type = "bool", default = false, desc = "Whether this test is being run as from CI"}
isNightly = {type = "bool", default = false, desc = "Whether this test is being run as part of the nightly test suite"}
networkJitter = {type = "int", unit = "milliseconds", default = 0}
networkLatency = {type = "int", unit = "milliseconds", default = 0}
numOfHubs = {type = "int", default = 3, desc = "The number of instances that should play the role of the hub"}
numOfIntermediaries = {type = "int", default = 2, desc = "The number of intermediaries(hops) to use in the virtual payment channel"}
numOfPayeePayers = {type = "int", default = 0, desc = "The number of instances that should play the role of the payeepayer"}
numOfPayees = {type = "int", default = 4, desc = "The number of instances that should play the role of the payee"}
numOfPayers = {type = "int", default = 1, desc = "The number of instances that should play the role of the payer"}
paymentTestDuration = {type = "int", default = 10, unit = "seconds"}
213 changes: 0 additions & 213 deletions tests/multi-hop-virtual-payment.go

This file was deleted.

34 changes: 19 additions & 15 deletions tests/virtual-payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
const START_PORT = 49000

func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) error {

// The default frequency of diagnostics is 10 seconds.
// That's a bit too slow for most of our test runs.
runEnv.D().SetFrequency(1 * time.Second)
ctx := context.Background()

client := init.SyncClient
Expand Down Expand Up @@ -69,9 +71,9 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err
mePeerInfo := peer.PeerInfo{PeerInfo: p2pms.PeerInfo{Address: address, IpAddress: ipAddress, Port: port, Id: ms.Id()}, Role: role, Seq: seq}
me := peer.MyInfo{PeerInfo: mePeerInfo, PrivateKey: *privateKey}

runEnv.RecordMessage("I am %+v", me)
runEnv.RecordMessage("I am address:%s role:%d seq:%d", me.Address, me.Role, me.Seq)

utils.RecordRunInfo(me, runConfig, runEnv.R())
utils.RecordRunInfo(me, runConfig, runEnv.D())

// Broadcasts our info and get peer info from all other instances.
peers := utils.SharePeerInfo(me.PeerInfo, ctx, client, runEnv.TestInstanceCount)
Expand All @@ -94,7 +96,7 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err
client.MustSignalEntry(ctx, contractSetup)
client.MustBarrier(ctx, contractSetup, runEnv.TestInstanceCount)

nClient := nitro.New(ms, cs, store, logDestination, &engine.PermissivePolicy{}, runEnv.R())
nClient := nitro.New(ms, cs, store, logDestination, &engine.PermissivePolicy{}, runEnv.D())

cm := utils.NewCompletionMonitor(&nClient, runEnv.RecordMessage)
defer cm.Close()
Expand All @@ -104,14 +106,13 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err

client.MustSignalAndWait(ctx, "message service connected", runEnv.TestInstanceCount)

ledgerIds := []types.Destination{}

if me.Role != peer.Hub {
// Create ledger channels with all the hubs
ledgerIds = utils.CreateLedgerChannels(nClient, cm, utils.FINNEY_IN_WEI, me.PeerInfo, peers)

ledgerIds := utils.CreateLedgerChannels(nClient, cm, utils.FINNEY_IN_WEI, me.PeerInfo, peers)
if len(ledgerIds) > 0 {
runEnv.RecordMessage("%s: Created Ledgers %s", me.Address, utils.AbbreviateSlice(ledgerIds))
}

// Create ledger channels with all the hubs

client.MustSignalAndWait(ctx, sync.State("ledgerDone"), runEnv.TestInstanceCount)

if me.IsPayer() {
Expand All @@ -121,11 +122,14 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err
payees = append(payees, peer.FilterByRole(peers, peer.PayerPayee)...)

createVirtualPaymentsJob := func() {
randomHub := utils.SelectRandom(hubs)
numHops := runEnv.IntParam("numOfIntermediaries")

selectedHubs := utils.SelectRandomHubs(hubs, numHops)
runEnv.RecordMessage("%s: Selected hubs %s", me.Address, utils.AbbreviateSlice(selectedHubs))
randomPayee := utils.SelectRandom(payees)

var channelId types.Destination
runEnv.R().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).Time(func() {
runEnv.D().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).Time(func() {

outcome := outcome.Exit{outcome.SingleAssetExit{
Allocations: outcome.Allocations{
Expand All @@ -140,12 +144,12 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err
},
}}

r := nClient.CreateVirtualPaymentChannel([]types.Address{randomHub.Address}, randomPayee.Address, 0, outcome)
r := nClient.CreateVirtualPaymentChannel(selectedHubs, randomPayee.Address, 0, outcome)

channelId = r.ChannelId
cm.WaitForObjectivesToComplete([]protocols.ObjectiveId{r.Id})

runEnv.RecordMessage("Opened virtual channel %s with %s using hub %s", utils.Abbreviate(channelId), utils.Abbreviate(randomPayee.Address), utils.Abbreviate(randomHub.Address))
runEnv.RecordMessage("Opened virtual channel %s with %s using hubs %s", utils.Abbreviate(channelId), utils.Abbreviate(randomPayee.Address), utils.AbbreviateSlice(selectedHubs))

paymentAmount := big.NewInt(utils.KWEI_IN_WEI)
nClient.Pay(r.ChannelId, paymentAmount)
Expand Down Expand Up @@ -197,7 +201,7 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err

// Record the mean time to first payment to nightly/ci metrics if applicable
// This allows us to track performance over time
mean := runEnv.R().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).Mean()
mean := runEnv.D().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).Mean()
if runEnv.BooleanParam("isNightly") {
runEnv.R().RecordPoint(fmt.Sprintf("nightly_mean_time_to_first_payment,me=%s", me.Address), float64(mean))
}
Expand Down

0 comments on commit c7c103f

Please sign in to comment.