Update to latest versions of nitro and questionable

This commit is contained in:
Mark Spanbroek 2021-04-15 11:23:49 +02:00 committed by markspanbroek
parent 753bde7775
commit 2d4a735e5f
5 changed files with 13 additions and 13 deletions

View File

@ -13,7 +13,7 @@ requires "nim >= 1.2.6",
"secp256k1",
"stew#head",
"protobufserialization >= 0.2.0 & < 0.3.0",
"https://github.com/status-im/nim-nitro >= 0.2.0 & < 0.3.0",
"questionable >= 0.5.0 & < 0.6.0",
"https://github.com/status-im/nim-nitro >= 0.4.0 & < 0.5.0",
"questionable >= 0.7.0 & < 0.8.0",
"upraises >= 0.1.0 & < 0.2.0",
"asynctest >= 0.2.1 & < 0.3.0"

View File

@ -284,8 +284,8 @@ proc setupPeer*(b: BitswapEngine, peer: PeerID) =
if b.wantList.len > 0:
b.request.sendWantList(peer, b.wantList, full = true)
if b.pricing.isSome:
b.request.sendPricing(peer, b.pricing.get)
if pricing =? b.pricing:
b.request.sendPricing(peer, pricing)
proc dropPeer*(b: BitswapEngine, peer: PeerID) =
## Cleanup disconnected peer

View File

@ -19,13 +19,13 @@ func openLedgerChannel*(wallet: var Wallet,
func getOrOpenChannel(wallet: var Wallet, peer: BitswapPeerCtx): ?!ChannelId =
if channel =? peer.paymentChannel:
channel.success
success channel
elif pricing =? peer.pricing:
let channel = ?wallet.openLedgerChannel(pricing.address, pricing.asset)
peer.paymentChannel = channel.some
channel.success
success channel
else:
ChannelId.failure "no pricing set for peer"
failure "no pricing set for peer"
func pay*(wallet: var Wallet,
peer: BitswapPeerCtx,
@ -37,4 +37,4 @@ func pay*(wallet: var Wallet,
let channel = ?wallet.getOrOpenChannel(peer)
wallet.pay(channel, asset, receiver, amount)
else:
SignedState.failure "no pricing set for peer"
failure "no pricing set for peer"

View File

@ -15,15 +15,15 @@ suite "engine payments":
peer.pricing = Pricing.example.some
test "pays for received bytes":
let payment = wallet.pay(peer, amountOfBytes).get
let pricing = peer.pricing.get
let payment = !wallet.pay(peer, amountOfBytes)
let pricing = !peer.pricing
let balances = payment.state.outcome.balances(pricing.asset)
let destination = pricing.address.toDestination
check balances[destination].get == amountOfBytes.u256 * pricing.price
check !balances[destination] == amountOfBytes.u256 * pricing.price
test "no payment when no price is set":
peer.pricing = Pricing.none
check wallet.pay(peer, amountOfBytes).isErr
check wallet.pay(peer, amountOfBytes).isFailure
test "uses same channel for consecutive payments":
let payment1, payment2 = wallet.pay(peer, amountOfBytes)

View File

@ -155,7 +155,7 @@ suite "Bitswap engine handlers":
engine.request.sendPayment = proc(receiver: PeerID, payment: SignedState) =
let amount = blocks.mapIt(it.data.len).foldl(a+b).u256 * pricing.price
let balances = payment.state.outcome.balances(pricing.asset).get
let balances = !payment.state.outcome.balances(pricing.asset)
check receiver == peerId
check balances[pricing.address.toDestination] == amount
done.complete()