mirror of https://github.com/waku-org/nwaku.git
chore: run nph linter manually
This commit is contained in:
parent
d7f2a33414
commit
363d56c980
|
@ -1,3 +1 @@
|
||||||
import
|
import ./test_rpc_codec, ./test_poc
|
||||||
./test_rpc_codec,
|
|
||||||
./test_poc
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ const TxHashSimpleTransfer* =
|
||||||
const EthClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9"
|
const EthClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9"
|
||||||
|
|
||||||
suite "Waku Incentivization PoC Eligibility Proofs":
|
suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
|
|
||||||
## Tests for service incentivization PoC.
|
## Tests for service incentivization PoC.
|
||||||
## In a client-server interaction, a client submits an eligibility proof to the server.
|
## In a client-server interaction, a client submits an eligibility proof to the server.
|
||||||
## The server provides the service if and only if the proof is valid.
|
## The server provides the service if and only if the proof is valid.
|
||||||
|
@ -35,7 +34,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
## The request is eligible if the tx is confirmed and pays the correct amount to the correct address.
|
## The request is eligible if the tx is confirmed and pays the correct amount to the correct address.
|
||||||
## The tx must also be of a "simple transfer" type (not a contract creation, not a contract call).
|
## The tx must also be of a "simple transfer" type (not a contract creation, not a contract call).
|
||||||
## See spec: https://github.com/waku-org/specs/blob/master/standards/core/incentivization.md
|
## See spec: https://github.com/waku-org/specs/blob/master/standards/core/incentivization.md
|
||||||
|
|
||||||
asyncTest "incentivization PoC: non-existent tx is not eligible":
|
asyncTest "incentivization PoC: non-existent tx is not eligible":
|
||||||
## Test that an unconfirmed tx is not eligible.
|
## Test that an unconfirmed tx is not eligible.
|
||||||
let eligibilityProof =
|
let eligibilityProof =
|
||||||
|
@ -43,7 +42,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
||||||
check:
|
check:
|
||||||
not txIsEligible
|
not txIsEligible
|
||||||
|
|
||||||
asyncTest "incentivization PoC: contract creation tx is not eligible":
|
asyncTest "incentivization PoC: contract creation tx is not eligible":
|
||||||
## Test that a contract creation tx is not eligible.
|
## Test that a contract creation tx is not eligible.
|
||||||
let eligibilityProof =
|
let eligibilityProof =
|
||||||
|
@ -51,7 +50,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
||||||
check:
|
check:
|
||||||
not txIsEligible
|
not txIsEligible
|
||||||
|
|
||||||
asyncTest "incentivization PoC: contract call tx is not eligible":
|
asyncTest "incentivization PoC: contract call tx is not eligible":
|
||||||
## Test that a contract call tx is not eligible.
|
## Test that a contract call tx is not eligible.
|
||||||
## This assumes a payment in native currency (ETH), not a token.
|
## This assumes a payment in native currency (ETH), not a token.
|
||||||
|
@ -60,7 +59,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
let txIsEligible = await isEligible(eligibilityProof, EthClient)
|
||||||
check:
|
check:
|
||||||
not txIsEligible
|
not txIsEligible
|
||||||
|
|
||||||
asyncTest "incentivization PoC: simple transfer tx is eligible":
|
asyncTest "incentivization PoC: simple transfer tx is eligible":
|
||||||
## Test that a simple transfer tx is eligible (if necessary conditions hold).
|
## Test that a simple transfer tx is eligible (if necessary conditions hold).
|
||||||
let eligibilityProof =
|
let eligibilityProof =
|
||||||
|
@ -68,5 +67,5 @@ suite "Waku Incentivization PoC Eligibility Proofs":
|
||||||
let txIdExists = await isEligible(eligibilityProof, EthClient)
|
let txIdExists = await isEligible(eligibilityProof, EthClient)
|
||||||
check:
|
check:
|
||||||
txIdExists
|
txIdExists
|
||||||
|
|
||||||
# TODO: add tests for simple transfer txs with wrong amount and wrong receiver
|
# TODO: add tests for simple transfer txs with wrong amount and wrong receiver
|
||||||
|
|
|
@ -1,35 +1,22 @@
|
||||||
import
|
import std/options, testutils/unittests, chronos, libp2p/crypto/crypto, web3
|
||||||
std/options,
|
|
||||||
testutils/unittests,
|
|
||||||
chronos,
|
|
||||||
libp2p/crypto/crypto,
|
|
||||||
web3
|
|
||||||
|
|
||||||
import
|
|
||||||
waku/incentivization/[
|
|
||||||
rpc,
|
|
||||||
rpc_codec,
|
|
||||||
common
|
|
||||||
]
|
|
||||||
|
|
||||||
|
import waku/incentivization/[rpc, rpc_codec, common]
|
||||||
|
|
||||||
suite "Waku Incentivization Eligibility Codec":
|
suite "Waku Incentivization Eligibility Codec":
|
||||||
|
|
||||||
asyncTest "encode eligibility proof from txid":
|
asyncTest "encode eligibility proof from txid":
|
||||||
let txHash = TxHash.fromHex(
|
let txHash = TxHash.fromHex(
|
||||||
"0x0000000000000000000000000000000000000000000000000000000000000000")
|
"0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
)
|
||||||
let txHashAsBytes = @(txHash.bytes())
|
let txHashAsBytes = @(txHash.bytes())
|
||||||
let eligibilityProof = EligibilityProof(proofOfPayment: some(txHashAsBytes))
|
let eligibilityProof = EligibilityProof(proofOfPayment: some(txHashAsBytes))
|
||||||
let encoded = encode(eligibilityProof)
|
let encoded = encode(eligibilityProof)
|
||||||
let decoded = EligibilityProof.decode(encoded.buffer).get()
|
let decoded = EligibilityProof.decode(encoded.buffer).get()
|
||||||
check:
|
check:
|
||||||
eligibilityProof == decoded
|
eligibilityProof == decoded
|
||||||
|
|
||||||
asyncTest "encode eligibility status":
|
asyncTest "encode eligibility status":
|
||||||
let eligibilityStatus = new(EligibilityStatus, true)
|
let eligibilityStatus = new(EligibilityStatus, true)
|
||||||
let encoded = encode(eligibilityStatus)
|
let encoded = encode(eligibilityStatus)
|
||||||
let decoded = EligibilityStatus.decode(encoded.buffer).get()
|
let decoded = EligibilityStatus.decode(encoded.buffer).get()
|
||||||
check:
|
check:
|
||||||
eligibilityStatus == decoded
|
eligibilityStatus == decoded
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,15 @@ import std/options, chronos
|
||||||
|
|
||||||
import waku/incentivization/[rpc, txid_proof]
|
import waku/incentivization/[rpc, txid_proof]
|
||||||
|
|
||||||
proc new*(
|
proc new*(T: type EligibilityStatus, isEligible: bool): T =
|
||||||
T: type EligibilityStatus,
|
|
||||||
isEligible: bool
|
|
||||||
): T =
|
|
||||||
if isEligible:
|
if isEligible:
|
||||||
EligibilityStatus(
|
EligibilityStatus(statusCode: uint32(200), statusDesc: some("OK"))
|
||||||
statusCode: uint32(200),
|
|
||||||
statusDesc: some("OK"))
|
|
||||||
else:
|
else:
|
||||||
EligibilityStatus(
|
EligibilityStatus(statusCode: uint32(402), statusDesc: some("Payment Required"))
|
||||||
statusCode: uint32(402),
|
|
||||||
statusDesc: some("Payment Required"))
|
|
||||||
|
|
||||||
proc isEligible*(eligibilityProof: EligibilityProof, ethClient: string): Future[bool] {.async.} =
|
proc isEligible*(
|
||||||
|
eligibilityProof: EligibilityProof, ethClient: string
|
||||||
|
): Future[bool] {.async.} =
|
||||||
## We consider a tx eligible,
|
## We consider a tx eligible,
|
||||||
## in the context of service incentivization PoC,
|
## in the context of service incentivization PoC,
|
||||||
## if it is confirmed and pays the expected amount to the server's address.
|
## if it is confirmed and pays the expected amount to the server's address.
|
||||||
|
|
|
@ -25,7 +25,8 @@ proc checkTxIdIsEligible(txHash: TxHash, ethClient: string): Future[bool] {.asyn
|
||||||
let hasExpectedValue = (txValue == 200500000000005063.u256)
|
let hasExpectedValue = (txValue == 200500000000005063.u256)
|
||||||
# check that the to address is "as expected" (hard-coded for now)
|
# check that the to address is "as expected" (hard-coded for now)
|
||||||
let toAddress = toAddressOption.get()
|
let toAddress = toAddressOption.get()
|
||||||
let hasExpectedToAddress = (toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
|
let hasExpectedToAddress =
|
||||||
|
(toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
|
||||||
defer:
|
defer:
|
||||||
await web3.close()
|
await web3.close()
|
||||||
return hasExpectedValue and hasExpectedToAddress
|
return hasExpectedValue and hasExpectedToAddress
|
||||||
|
|
Loading…
Reference in New Issue