Skip to content

Commit

Permalink
add eligibility tests by txid
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tikhomirov committed Nov 1, 2024
1 parent ed08759 commit 24f9aa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 10 additions & 12 deletions tests/incentivization/test_poc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import
rpc,
rpc_codec,
common,
txid_proof
txid_proof,
eligibility
]


Expand All @@ -33,20 +34,17 @@ const TxHashNonExisting* = TxHash.fromHex(
const EthClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9"


#suite "Waku Incentivization PoC Eligibility Proofs":
suite "Waku Incentivization PoC Eligibility Proofs":

# TODO: test eligibility without dummy protocol

#[
asyncTest "incentivization PoC: dummy protocol with a valid txid eligibility proof":
let request = genDummyRequestWithTxIdEligibilityProof(@(TxHashExisting.bytes()))
let response = await client.sendRequest(request, serverRemotePeerInfo)
let eligibilityProof = EligibilityProof(proofOfPayment: some(@(TxHashExisting.bytes())))
let txIdExists = await isEligible(eligibilityProof, EthClient)
check:
response.isOk()
txIdExists

asyncTest "incentivization PoC: dummy protocol client with an invalid txid eligibility proof":
let request = genDummyRequestWithTxIdEligibilityProof(@(TxHashNonExisting.bytes()))
let response = await client.sendRequest(request, serverRemotePeerInfo)
let eligibilityProof = EligibilityProof(proofOfPayment: some(@(TxHashNonExisting.bytes())))
let txIdExists = await isEligible(eligibilityProof, EthClient)
check:
response.isErr()
]#
not txIdExists

8 changes: 6 additions & 2 deletions tests/incentivization/test_rpc_codec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ import
eligibility
]

#[
let txHash = TxHash.fromHex(
"0x0000000000000000000000000000000000000000000000000000000000000000"
)
let txHashAsBytes = @(txHash.bytes())
]#

suite "Waku Incentivization Eligibility Codec":
asyncTest "encode eligibility proof":

asyncTest "encode eligibility proof from bytes":
# FIXME: remove this test?
var byteSequence: seq[byte] = @[1, 2, 3, 4, 5, 6, 7, 8]
let epRpc = EligibilityProof(proofOfPayment: some(byteSequence))
let encoded = encode(epRpc)
let decoded = EligibilityProof.decode(encoded.buffer).get()
check:
epRpc == decoded

asyncTest "encode eligibility proof":
asyncTest "encode eligibility proof from txid":
let txHash = TxHash.fromHex(
"0x0000000000000000000000000000000000000000000000000000000000000000")
let txHashAsBytes = @(txHash.bytes())
Expand Down

0 comments on commit 24f9aa8

Please sign in to comment.