Update to latest versions of nitro and questionable
This commit is contained in:
parent
753bde7775
commit
2d4a735e5f
|
@ -13,7 +13,7 @@ requires "nim >= 1.2.6",
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"stew#head",
|
"stew#head",
|
||||||
"protobufserialization >= 0.2.0 & < 0.3.0",
|
"protobufserialization >= 0.2.0 & < 0.3.0",
|
||||||
"https://github.com/status-im/nim-nitro >= 0.2.0 & < 0.3.0",
|
"https://github.com/status-im/nim-nitro >= 0.4.0 & < 0.5.0",
|
||||||
"questionable >= 0.5.0 & < 0.6.0",
|
"questionable >= 0.7.0 & < 0.8.0",
|
||||||
"upraises >= 0.1.0 & < 0.2.0",
|
"upraises >= 0.1.0 & < 0.2.0",
|
||||||
"asynctest >= 0.2.1 & < 0.3.0"
|
"asynctest >= 0.2.1 & < 0.3.0"
|
||||||
|
|
|
@ -284,8 +284,8 @@ proc setupPeer*(b: BitswapEngine, peer: PeerID) =
|
||||||
if b.wantList.len > 0:
|
if b.wantList.len > 0:
|
||||||
b.request.sendWantList(peer, b.wantList, full = true)
|
b.request.sendWantList(peer, b.wantList, full = true)
|
||||||
|
|
||||||
if b.pricing.isSome:
|
if pricing =? b.pricing:
|
||||||
b.request.sendPricing(peer, b.pricing.get)
|
b.request.sendPricing(peer, pricing)
|
||||||
|
|
||||||
proc dropPeer*(b: BitswapEngine, peer: PeerID) =
|
proc dropPeer*(b: BitswapEngine, peer: PeerID) =
|
||||||
## Cleanup disconnected peer
|
## Cleanup disconnected peer
|
||||||
|
|
|
@ -19,13 +19,13 @@ func openLedgerChannel*(wallet: var Wallet,
|
||||||
|
|
||||||
func getOrOpenChannel(wallet: var Wallet, peer: BitswapPeerCtx): ?!ChannelId =
|
func getOrOpenChannel(wallet: var Wallet, peer: BitswapPeerCtx): ?!ChannelId =
|
||||||
if channel =? peer.paymentChannel:
|
if channel =? peer.paymentChannel:
|
||||||
channel.success
|
success channel
|
||||||
elif pricing =? peer.pricing:
|
elif pricing =? peer.pricing:
|
||||||
let channel = ?wallet.openLedgerChannel(pricing.address, pricing.asset)
|
let channel = ?wallet.openLedgerChannel(pricing.address, pricing.asset)
|
||||||
peer.paymentChannel = channel.some
|
peer.paymentChannel = channel.some
|
||||||
channel.success
|
success channel
|
||||||
else:
|
else:
|
||||||
ChannelId.failure "no pricing set for peer"
|
failure "no pricing set for peer"
|
||||||
|
|
||||||
func pay*(wallet: var Wallet,
|
func pay*(wallet: var Wallet,
|
||||||
peer: BitswapPeerCtx,
|
peer: BitswapPeerCtx,
|
||||||
|
@ -37,4 +37,4 @@ func pay*(wallet: var Wallet,
|
||||||
let channel = ?wallet.getOrOpenChannel(peer)
|
let channel = ?wallet.getOrOpenChannel(peer)
|
||||||
wallet.pay(channel, asset, receiver, amount)
|
wallet.pay(channel, asset, receiver, amount)
|
||||||
else:
|
else:
|
||||||
SignedState.failure "no pricing set for peer"
|
failure "no pricing set for peer"
|
||||||
|
|
|
@ -15,15 +15,15 @@ suite "engine payments":
|
||||||
peer.pricing = Pricing.example.some
|
peer.pricing = Pricing.example.some
|
||||||
|
|
||||||
test "pays for received bytes":
|
test "pays for received bytes":
|
||||||
let payment = wallet.pay(peer, amountOfBytes).get
|
let payment = !wallet.pay(peer, amountOfBytes)
|
||||||
let pricing = peer.pricing.get
|
let pricing = !peer.pricing
|
||||||
let balances = payment.state.outcome.balances(pricing.asset)
|
let balances = payment.state.outcome.balances(pricing.asset)
|
||||||
let destination = pricing.address.toDestination
|
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":
|
test "no payment when no price is set":
|
||||||
peer.pricing = Pricing.none
|
peer.pricing = Pricing.none
|
||||||
check wallet.pay(peer, amountOfBytes).isErr
|
check wallet.pay(peer, amountOfBytes).isFailure
|
||||||
|
|
||||||
test "uses same channel for consecutive payments":
|
test "uses same channel for consecutive payments":
|
||||||
let payment1, payment2 = wallet.pay(peer, amountOfBytes)
|
let payment1, payment2 = wallet.pay(peer, amountOfBytes)
|
||||||
|
|
|
@ -155,7 +155,7 @@ suite "Bitswap engine handlers":
|
||||||
|
|
||||||
engine.request.sendPayment = proc(receiver: PeerID, payment: SignedState) =
|
engine.request.sendPayment = proc(receiver: PeerID, payment: SignedState) =
|
||||||
let amount = blocks.mapIt(it.data.len).foldl(a+b).u256 * pricing.price
|
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 receiver == peerId
|
||||||
check balances[pricing.address.toDestination] == amount
|
check balances[pricing.address.toDestination] == amount
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
Loading…
Reference in New Issue