2026-07-16 14:02:17 -03:00
|
|
|
import results, testutils/unittests, chronos, web3
|
2025-02-20 16:07:21 +01:00
|
|
|
|
2026-06-08 13:37:53 +02:00
|
|
|
import
|
|
|
|
|
logos_delivery/waku/incentivization/reputation_manager,
|
|
|
|
|
logos_delivery/waku/waku_lightpush_legacy/rpc
|
2025-02-20 16:07:21 +01:00
|
|
|
|
|
|
|
|
suite "Waku Incentivization PoC Reputation":
|
|
|
|
|
var manager {.threadvar.}: ReputationManager
|
|
|
|
|
|
|
|
|
|
setup:
|
|
|
|
|
manager = ReputationManager.init()
|
|
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: reputation table is empty after initialization":
|
|
|
|
|
check manager.reputationOf.len == 0
|
|
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: set and get reputation":
|
2026-07-16 14:02:17 -03:00
|
|
|
manager.setReputation("peer1", Opt.some(true)) # Encodes GoodRep
|
|
|
|
|
check manager.getReputation("peer1") == Opt.some(true)
|
2025-02-20 16:07:21 +01:00
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: evaluate PushResponse valid":
|
|
|
|
|
let validLightpushResponse =
|
2026-07-16 14:02:17 -03:00
|
|
|
PushResponse(isSuccess: true, info: Opt.some("Everything is OK"))
|
2025-02-20 16:07:21 +01:00
|
|
|
# We expect evaluateResponse to return GoodResponse if isSuccess is true
|
|
|
|
|
check evaluateResponse(validLightpushResponse) == GoodResponse
|
|
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: evaluate PushResponse invalid":
|
2026-07-16 14:02:17 -03:00
|
|
|
let invalidLightpushResponse =
|
|
|
|
|
PushResponse(isSuccess: false, info: Opt.none(string))
|
2025-02-20 16:07:21 +01:00
|
|
|
check evaluateResponse(invalidLightpushResponse) == BadResponse
|
|
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: updateReputationFromResponse valid":
|
|
|
|
|
let peerId = "peerWithValidResponse"
|
2026-07-16 14:02:17 -03:00
|
|
|
let validResp = PushResponse(isSuccess: true, info: Opt.some("All good"))
|
2025-02-20 16:07:21 +01:00
|
|
|
manager.updateReputationFromResponse(peerId, validResp)
|
2026-07-16 14:02:17 -03:00
|
|
|
check manager.getReputation(peerId) == Opt.some(true)
|
2025-02-20 16:07:21 +01:00
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: updateReputationFromResponse invalid":
|
|
|
|
|
let peerId = "peerWithInvalidResponse"
|
2026-07-16 14:02:17 -03:00
|
|
|
let invalidResp = PushResponse(isSuccess: false, info: Opt.none(string))
|
2025-02-20 16:07:21 +01:00
|
|
|
manager.updateReputationFromResponse(peerId, invalidResp)
|
2026-07-16 14:02:17 -03:00
|
|
|
check manager.getReputation(peerId) == Opt.some(false)
|
2025-02-20 16:07:21 +01:00
|
|
|
|
|
|
|
|
test "incentivization PoC: reputation: default is None":
|
|
|
|
|
let unknownPeerId = "unknown_peer"
|
|
|
|
|
# The peer is not in the table yet
|
2026-07-16 14:02:17 -03:00
|
|
|
check manager.getReputation(unknownPeerId) == Opt.none(bool)
|