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(plugin-persistence-ethereum): fix broken postgresql-db-client.test #3373

Closed
petermetz opened this issue Jul 2, 2024 · 1 comment · Fixed by #3374 or #3376
Closed

test(plugin-persistence-ethereum): fix broken postgresql-db-client.test #3373

petermetz opened this issue Jul 2, 2024 · 1 comment · Fixed by #3374 or #3376
Assignees
Labels
Flaky-Test-Automation Issues related to test stability (which is a long running issue that can never fully be solved) good-first-issue-200-intermediate Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. P4 Priority 4: Low Tests Anything related to tests be that automatic or manual, integration or unit, etc.
Milestone

Comments

@petermetz
Copy link
Contributor

petermetz commented Jul 2, 2024

Description

One of the test cases is failing consistently on my local environment.
It's an assertion that compares dates so I'm guessing it might be a problem of time zones not being explicitly specified somewhere in the test environment and then it defaults to California time on my machine. Just a guess though.

The file that has the failing test: packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts

Screenshot of logs:

image

The Logs

$ yarn jest packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts
jest-haste-map: duplicate manual mock found: ConfigUtil
  The following files share their name; please delete one of them:
    * <rootDir>/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/util/__mocks__/ConfigUtil.ts
    * <rootDir>/packages/cactus-cmd-socketio-server/dist/lib/main/typescript/routing-interface/util/__mocks__/ConfigUtil.js

[2024-07-02T16:37:32.128Z] INFO (persistence-ethereum-postgresql-db-client.test): Prune Docker...
[2024-07-02T16:37:32.129Z] INFO (persistence-ethereum-postgresql-db-client.test): Run PostgresTestContainer...
[2024-07-02T16:37:44.670Z] INFO (persistence-ethereum-postgresql-db-client.test): Postgres running at 127.0.0.1:32973
[2024-07-02T16:37:44.670Z] INFO (persistence-ethereum-postgresql-db-client.test): Create PostgresDatabaseClient
[2024-07-02T16:37:44.672Z] INFO (persistence-ethereum-postgresql-db-client.test): Connect the PostgreSQL PostgresDatabaseClient
[2024-07-02T16:37:44.672Z] INFO (PostgresDatabaseClient): Connect to PostgreSQL database...
[2024-07-02T16:37:44.698Z] INFO (persistence-ethereum-postgresql-db-client.test): Mock Supabase schema
[2024-07-02T16:37:44.715Z] INFO (persistence-ethereum-postgresql-db-client.test): Initialize the test DB Schema
[2024-07-02T16:37:44.716Z] INFO (PostgresDatabaseClient): No status in the DB for plugin TestPlugin
[2024-07-02T16:37:44.716Z] INFO (PostgresDatabaseClient): Path to SQL script to create a database schema: /home/peter/a/cacti/packages/cactus-plugin-persistence-ethereum/src/main/sql/schema.sql
[2024-07-02T16:37:44.827Z] INFO (PostgresDatabaseClient): Schema DB initialized.
[2024-07-02T16:37:44.828Z] INFO (PostgresDatabaseClient): Update status for plugin TestPlugin with instanceId testInstance
[2024-07-02T16:37:44.836Z] INFO (persistence-ethereum-postgresql-db-client.test): Ensure DB Schema is empty (in case test is re-run on same DB
[2024-07-02T16:37:44.860Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc20
[2024-07-02T16:37:44.865Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc20
[2024-07-02T16:37:44.891Z] INFO (PostgresDatabaseClient): Update status for plugin TestPlugin with instanceId testInstance
[2024-07-02T16:37:44.916Z] WARN (PostgresDatabaseClient): Instance ID in DB different from this plugin id (testInstance != AnotherInstance)! Make sure only one persistence plugin is running at a time!
[2024-07-02T16:37:44.916Z] INFO (PostgresDatabaseClient): Update status for plugin TestPlugin with instanceId AnotherInstance
[2024-07-02T16:37:44.947Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:44.951Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:44.984Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:45.070Z] WARN (PostgresDatabaseClient): insertBlockData() exception: error: invalid input syntax for type numeric: "asd"
    at Parser.parseErrorMessage (/home/peter/a/cacti/packages/cactus-plugin-persistence-ethereum/node_modules/pg-protocol/src/parser.ts:369:69)
    at Parser.handlePacket (/home/peter/a/cacti/packages/cactus-plugin-persistence-ethereum/node_modules/pg-protocol/src/parser.ts:188:21)
    at Parser.parse (/home/peter/a/cacti/packages/cactus-plugin-persistence-ethereum/node_modules/pg-protocol/src/parser.ts:103:30)
    at Socket.<anonymous> (/home/peter/a/cacti/packages/cactus-plugin-persistence-ethereum/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Socket.Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 144,
  severity: 'ERROR',
  code: '22P02',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: "unnamed portal parameter $4 = '...'",
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'numeric.c',
  line: '6856',
  routine: 'set_var_from_str'
}
[2024-07-02T16:37:45.075Z] INFO (persistence-ethereum-postgresql-db-client.test): insertBlockData was rejected as expected
[2024-07-02T16:37:45.101Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc20
[2024-07-02T16:37:45.178Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:45.315Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:45.395Z] INFO (PostgresDatabaseClient): Inserted 1 rows into table token_metadata_erc721
[2024-07-02T16:37:45.461Z] INFO (persistence-ethereum-postgresql-db-client.test): FINISHING THE TESTS
[2024-07-02T16:37:45.461Z] INFO (persistence-ethereum-postgresql-db-client.test): Disconnect the PostgresDatabaseClient
[2024-07-02T16:37:45.461Z] INFO (PostgresDatabaseClient): Close connection with PostgreSQL database.
[2024-07-02T16:37:45.463Z] INFO (persistence-ethereum-postgresql-db-client.test): Stop PostgreSQL...
[2024-07-02T16:37:46.031Z] INFO (persistence-ethereum-postgresql-db-client.test): Prune Docker...
 FAIL  packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts (16.189 s, 127 MB heap size)
  Ethereum persistence PostgreSQL PostgresDatabaseClient tests
    ✓ Insert single and get all ERC20 token metadata. (32 ms)
    ✓ Initialize plugin can be called repeatedly and it only updates the last_connected_at (24 ms)
    ✓ Initialize plugin updates instance ID when it changes (28 ms)
    ✓ Insert single and get all ERC721 token metadata. (39 ms)
    ✓ Upsert already issued ERC721 token into table (without duplication) (36 ms)
    ✕ New block data is added to the DB (49 ms)
    ✓ insertBlockData atomic transaction is reverted on error  (31 ms)
    ✓ ERC20 token balance is updated on new block (77 ms)
    ✓ ERC721 token balance is updated on new block (135 ms)
    ✓ Only ERC721 token owner and last_owner_change is updated on already issued token (79 ms)
    ✓ ERC721 token is not updated if if was updated after the transaction was committed (manual token sync) (69 ms)

  ● Ethereum persistence PostgreSQL PostgresDatabaseClient tests › New block data is added to the DB

    expect(received).toEqual(expected) // deep equality

    Expected: 2022-12-22T09:55:25.000Z
    Received: 2022-12-22T17:55:25.000Z

      361 |     expect(dbBlock.hash).toEqual(block.hash);
      362 |     expect(dbBlock.number_of_tx).toEqual(block.number_of_tx.toString());
    > 363 |     expect(new Date(dbBlock.created_at)).toEqual(blockTimestamp);
          |                                          ^
      364 |
      365 |     // Assert transaction
      366 |     const txResponse = await getDbTransactions();

      at Object.<anonymous> (packages/cactus-plugin-persistence-ethereum/src/test/typescript/integration/persistence-ethereum-postgresql-db-client.test.ts:363:42)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 10 passed, 11 total
Snapshots:   0 total
Time:        16.246 s
Ran all test suites matching /packages\/cactus-plugin-persistence-ethereum\/src\/test\/typescript\/integration\/persistence-ethereum-postgresql-db-client.test.ts/i.

Acceptance Criteria

  1. Test is passing consistently
@petermetz petermetz added Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. good-first-issue-200-intermediate Flaky-Test-Automation Issues related to test stability (which is a long running issue that can never fully be solved) Tests Anything related to tests be that automatic or manual, integration or unit, etc. P4 Priority 4: Low labels Jul 2, 2024
@petermetz petermetz added this to the v2.0.0 milestone Jul 2, 2024
@petermetz petermetz self-assigned this Jul 2, 2024
petermetz added a commit to petermetz/cacti that referenced this issue Jul 2, 2024
1. The problem was that the database schema was defined in a way that was
destroying timestamp information during insertion of records.
2. Updating the schema to hold the timestamp information made the test pass.

More information about why it's recommended to store datetime data with
the TIMESTAMPTZ column type is explained by the author of the node-postgres
library which is an important part of the problem (it assumes local time
for columns that do not store the timestamp time zone).

https://node-postgres.com/features/types#date--timestamp--timestamptz

Fixes hyperledger-cacti#3373

Signed-off-by: Peter Somogyvari <[email protected]>
@petermetz
Copy link
Contributor Author

^^I just submitted a fix

petermetz added a commit to petermetz/cacti that referenced this issue Jul 3, 2024
1. The problem was that the database schema was defined in a way that was
destroying timestamp information during insertion of records.
2. Updating the schema to hold the timestamp information made the test pass.

More information about why it's recommended to store datetime data with
the TIMESTAMPTZ column type is explained by the author of the node-postgres
library which is an important part of the problem (it assumes local time
for columns that do not store the timestamp time zone).

https://node-postgres.com/features/types#date--timestamp--timestamptz

Fixes hyperledger-cacti#3373

Signed-off-by: Peter Somogyvari <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Flaky-Test-Automation Issues related to test stability (which is a long running issue that can never fully be solved) good-first-issue-200-intermediate Hacktoberfest Hacktoberfest participants are welcome to take a stab at issues marked with this label. P4 Priority 4: Low Tests Anything related to tests be that automatic or manual, integration or unit, etc.
Projects
None yet
3 participants