chore: run nph linter manually

This commit is contained in:
Sergei Tikhomirov 2024-12-13 08:25:36 +01:00
parent d7f2a33414
commit 363d56c980
5 changed files with 20 additions and 40 deletions

View File

@ -1,3 +1 @@
import
./test_rpc_codec,
./test_poc
import ./test_rpc_codec, ./test_poc

View File

@ -26,7 +26,6 @@ const TxHashSimpleTransfer* =
const EthClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9"
suite "Waku Incentivization PoC Eligibility Proofs":
## Tests for service incentivization PoC.
## 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.
@ -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 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
asyncTest "incentivization PoC: non-existent tx is not eligible":
## Test that an unconfirmed tx is not eligible.
let eligibilityProof =
@ -43,7 +42,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
let txIsEligible = await isEligible(eligibilityProof, EthClient)
check:
not txIsEligible
asyncTest "incentivization PoC: contract creation tx is not eligible":
## Test that a contract creation tx is not eligible.
let eligibilityProof =
@ -51,7 +50,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
let txIsEligible = await isEligible(eligibilityProof, EthClient)
check:
not txIsEligible
asyncTest "incentivization PoC: 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.
@ -60,7 +59,7 @@ suite "Waku Incentivization PoC Eligibility Proofs":
let txIsEligible = await isEligible(eligibilityProof, EthClient)
check:
not txIsEligible
asyncTest "incentivization PoC: simple transfer tx is eligible":
## Test that a simple transfer tx is eligible (if necessary conditions hold).
let eligibilityProof =
@ -68,5 +67,5 @@ suite "Waku Incentivization PoC Eligibility Proofs":
let txIdExists = await isEligible(eligibilityProof, EthClient)
check:
txIdExists
# TODO: add tests for simple transfer txs with wrong amount and wrong receiver

View File

@ -1,35 +1,22 @@
import
std/options,
testutils/unittests,
chronos,
libp2p/crypto/crypto,
web3
import
waku/incentivization/[
rpc,
rpc_codec,
common
]
import std/options, testutils/unittests, chronos, libp2p/crypto/crypto, web3
import waku/incentivization/[rpc, rpc_codec, common]
suite "Waku Incentivization Eligibility Codec":
asyncTest "encode eligibility proof from txid":
let txHash = TxHash.fromHex(
"0x0000000000000000000000000000000000000000000000000000000000000000")
"0x0000000000000000000000000000000000000000000000000000000000000000"
)
let txHashAsBytes = @(txHash.bytes())
let eligibilityProof = EligibilityProof(proofOfPayment: some(txHashAsBytes))
let encoded = encode(eligibilityProof)
let decoded = EligibilityProof.decode(encoded.buffer).get()
check:
eligibilityProof == decoded
eligibilityProof == decoded
asyncTest "encode eligibility status":
let eligibilityStatus = new(EligibilityStatus, true)
let encoded = encode(eligibilityStatus)
let decoded = EligibilityStatus.decode(encoded.buffer).get()
check:
eligibilityStatus == decoded

View File

@ -2,20 +2,15 @@ import std/options, chronos
import waku/incentivization/[rpc, txid_proof]
proc new*(
T: type EligibilityStatus,
isEligible: bool
): T =
proc new*(T: type EligibilityStatus, isEligible: bool): T =
if isEligible:
EligibilityStatus(
statusCode: uint32(200),
statusDesc: some("OK"))
EligibilityStatus(statusCode: uint32(200), statusDesc: some("OK"))
else:
EligibilityStatus(
statusCode: uint32(402),
statusDesc: some("Payment Required"))
EligibilityStatus(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,
## in the context of service incentivization PoC,
## if it is confirmed and pays the expected amount to the server's address.

View File

@ -25,7 +25,8 @@ proc checkTxIdIsEligible(txHash: TxHash, ethClient: string): Future[bool] {.asyn
let hasExpectedValue = (txValue == 200500000000005063.u256)
# check that the to address is "as expected" (hard-coded for now)
let toAddress = toAddressOption.get()
let hasExpectedToAddress = (toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
let hasExpectedToAddress =
(toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284"))
defer:
await web3.close()
return hasExpectedValue and hasExpectedToAddress