Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test VRF LogPoller functionality- initializeLastProcessedBlock, updateLastProcessedBlock and getUnfulfilled #11472

Merged
merged 7 commits into from
Dec 7, 2023

Conversation

kidambisrinivas
Copy link
Collaborator

Goal

  • Add unit tests for the following functions in core/services/vrf/v2/listener_v2_log_listener.go
    • initializeLastProcessedBlock: Test should use the log poller and actually run a query on the DB, not mock the log poller's output
    • updateLastProcessedBlock: Test should use the log poller and actually run a query on the DB, not mock the log poller's output
    • getUnfulfilled: Doesn't need log poller, inputs can be generated

Note

Following Tests uses the log poller with a simulated chain and actually runs a query on the DB using pgtest.NewSqlxDB, not mock the log poller's output

  • initializeLastProcessedBlock
  • updateLastProcessedBlock

Dev Setup

$ ## Setup
cd chainlink
git fetch origin
git checkout feature/vrf-log-poller-tests
make chainlink-dev
make testdb
./scripts/native_solc_compile_all_logpoller

Testing

## Run all tests
$ go test -count=1 -v -run="^TestInitProcessedBlock_" -p 5 ./core/services/vrf/v2/...

## Run individual tests
$ go test -count=1 -v -run="^TestInitProcessedBlock_NoReqs$" ./core/services/vrf/v2/...
$ go test -count=1 -v -run="^TestInitProcessedBlock_NoUnfulfilledVRFReqs$" ./core/services/vrf/v2/...
$ go test -count=1 -v -run="^TestInitProcessedBlock_OneUnfulfilledVRFReq" ./core/services/vrf/v2/...
$ go test -count=1 -v -run="^TestInitProcessedBlock_SomeUnfulfilledVRFReqs" ./core/services/vrf/v2/...

$ go test -count=1 -v -run="^TestUpdateLastProcessedBlock_" ./core/services/vrf/v2/...
...
    chain.go:376: PASS: LogPoller()
--- PASS: TestUpdateLastProcessedBlock_NoUnfulfilledVRFReqs (0.09s)
PASS
ok      github.com/smartcontractkit/chainlink/v2/core/services/vrf/v2   1.949s

$ go test -count=1 -v -run="^TestGetUnfulfilled_" ./core/services/vrf/v2/...
...
PASS
ok      github.com/smartcontractkit/chainlink/v2/core/services/vrf/v2   0.922s

Test Logs

3-11-14 10:24:06 +0000 GMT, 17, NOW())     ON CONFLICT DO NOTHING"}
    logger.go:130: 2023-11-15T10:20:46.070Z     INFO    LogPoller       logpoller/log_poller.go:469     Executing replay finished       {"version": "unset@unset", "fromBlock": 1, "requested":
 1}
    logger.go:130: 2023-11-15T10:20:46.070Z     DEBUG   Configs pg/q.go:246     SQL QUERY       {"version": "unset@unset", "sql": "   SELECT * FROM evm.logs     WHERE evm_chain_id = 529100775
    AND address = '\\xdf5e2c26456367e499982140574d75a3a1b2eace'    AND event_sig = '\\x63373d1c4696214b898952999c9aaec57dac1ee2723cec59bea6888f489a9772'    AND topics[2] = ANY(('\\xc0a6c424ac
7157ae408398df7e5f4552091a69125d5dfcb7b8c2659029395bdf'))    AND block_timestamp > 2023-11-14 10:20:46.060582 +0000 UTC    AND block_number <=      (SELECT finalized_block_number      FROM ev
m.log_poller_blocks      WHERE evm_chain_id = 529100775      ORDER BY block_number DESC LIMIT 1)     ORDER BY (block_number, log_index)"}
    logger.go:130: 2023-11-15T10:20:46.071Z     DEBUG   Configs pg/q.go:246     SQL QUERY       {"version": "unset@unset", "sql": "   SELECT * FROM evm.logs      WHERE evm_chain_id = 52910077
5     AND address = '\\xdf5e2c26456367e499982140574d75a3a1b2eace'     AND event_sig = '\\x7dffc5ae5ee4e2e4df1651cf6ad329a73cebdb728f37ea0187b9b17e036756e4'     AND block_timestamp > 2023-11-1
4 10:20:46.060582 +0000 UTC     AND block_number <=      (SELECT finalized_block_number      FROM evm.log_poller_blocks      WHERE evm_chain_id = 529100775      ORDER BY block_number DESC LIM
IT 1)      ORDER BY (block_number, log_index)"}
    logger.go:130: 2023-11-15T10:20:46.072Z     INFO    v2/listener_v2_log_listener.go:311      found logs      {"version": "unset@unset", "latestFinalizedBlock": 17, "latestBlock": 20, "from
Timestamp": "2023-11-14T10:20:46.060Z", "fulfilled": 4, "requested": 8}
    logger.go:130: 2023-11-15T10:20:46.072Z     DEBUG   v2/listener_v2_log_listener.go:120      Done initializing last processed block  {"version": "unset@unset", "latestFinalizedBlock": 17,
"latestBlock": 20, "fromTimestamp": "2023-11-14T10:20:46.060Z", "elapsed": "12.412833ms"}

@kidambisrinivas kidambisrinivas requested review from RensR and a team as code owners December 4, 2023 12:26
Copy link
Contributor

github-actions bot commented Dec 4, 2023

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

Copy link
Contributor

github-actions bot commented Dec 4, 2023

I see that you haven't updated any README files. Would it make sense to do so?

@cl-sonarqube-production
Copy link

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kidambisrinivas kidambisrinivas added this pull request to the merge queue Dec 7, 2023
Merged via the queue into develop with commit 5a98ac6 Dec 7, 2023
86 checks passed
@kidambisrinivas kidambisrinivas deleted the feature/vrf-log-poller-tests-1 branch December 7, 2023 17:51
fbac pushed a commit that referenced this pull request Dec 14, 2023
…eLastProcessedBlock and getUnfulfilled (#11472)

* Test VRF LogPoller functionality- initializeLastProcessedBlock, updateLastProcessedBlock and getUnfulfilled

* Addressed PR comments

* Minor change

* Add comments to explain replay

* Addressed PR comments

* Prettier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants