Skip to content

Commit c058f0a

Browse files
authored
Merge pull request #143 from statechannels/fix-zeroes
Only add timer once we have a measurement
2 parents 74b2613 + d9d7c4f commit c058f0a

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

tests/virtual-payment.go

+21-23
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,33 @@ func CreateVirtualPaymentTest(runEnv *runtime.RunEnv, init *run.InitContext) err
123123
randomPayee := utils.SelectRandom(payees)
124124

125125
var channelId types.Destination
126-
runEnv.R().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).Time(func() {
127-
128-
outcome := outcome.Exit{outcome.SingleAssetExit{
129-
Allocations: outcome.Allocations{
130-
outcome.Allocation{
131-
Destination: types.AddressToDestination(me.Address),
132-
Amount: big.NewInt(int64(10 * utils.GWEI_IN_WEI)),
133-
},
134-
outcome.Allocation{
135-
Destination: types.AddressToDestination(randomPayee.Address),
136-
Amount: big.NewInt(0),
137-
},
126+
ttfpStart := time.Now()
127+
outcome := outcome.Exit{outcome.SingleAssetExit{
128+
Allocations: outcome.Allocations{
129+
outcome.Allocation{
130+
Destination: types.AddressToDestination(me.Address),
131+
Amount: big.NewInt(int64(10 * utils.GWEI_IN_WEI)),
138132
},
139-
}}
140-
141-
r := nClient.CreateVirtualPaymentChannel(selectedHubs, randomPayee.Address, 0, outcome)
133+
outcome.Allocation{
134+
Destination: types.AddressToDestination(randomPayee.Address),
135+
Amount: big.NewInt(0),
136+
},
137+
},
138+
}}
142139

143-
channelId = r.ChannelId
144-
cm.WaitForObjectivesToComplete([]protocols.ObjectiveId{r.Id})
140+
r := nClient.CreateVirtualPaymentChannel(selectedHubs, randomPayee.Address, 0, outcome)
145141

146-
runEnv.RecordMessage("Opened virtual channel %s with %s using hubs %s", utils.Abbreviate(channelId), utils.Abbreviate(randomPayee.Address), utils.AbbreviateSlice(selectedHubs))
142+
channelId = r.ChannelId
143+
cm.WaitForObjectivesToComplete([]protocols.ObjectiveId{r.Id})
147144

148-
paymentAmount := big.NewInt(utils.KWEI_IN_WEI)
149-
nClient.Pay(r.ChannelId, paymentAmount)
150-
runEnv.RecordMessage("Sent payment of %d wei to %s using channel %s", paymentAmount.Int64(), utils.Abbreviate(randomPayee.Address), utils.Abbreviate(channelId))
145+
runEnv.RecordMessage("Opened virtual channel %s with %s using hubs %s", utils.Abbreviate(channelId), utils.Abbreviate(randomPayee.Address), utils.AbbreviateSlice(selectedHubs))
151146

152-
// TODO: Should we wait for receipt of this payment before stopping the time_to_first_payment timer?
153-
})
147+
paymentAmount := big.NewInt(utils.KWEI_IN_WEI)
148+
nClient.Pay(r.ChannelId, paymentAmount)
149+
runEnv.RecordMessage("Sent payment of %d wei to %s using channel %s", paymentAmount.Int64(), utils.Abbreviate(randomPayee.Address), utils.Abbreviate(channelId))
154150

151+
// TODO: Should we wait for receipt of this payment before stopping the time_to_first_payment timer?
152+
runEnv.R().Timer(fmt.Sprintf("time_to_first_payment,me=%s", me.Address)).UpdateSince(ttfpStart)
155153
// Perform between 1 and 5 payments additional payments
156154
amountOfPayments := 1 + rand.Intn(4)
157155
for i := 0; i < amountOfPayments; i++ {

0 commit comments

Comments
 (0)