Skip to content

Commit

Permalink
feat(cactus-plugin-ledger-connector-ethereum): update web3js to 4.X
Browse files Browse the repository at this point in the history
- Update web3js packages from 1.10 to 4.0.3 in `cactus-plugin-ledger-connector-ethereum` and
    `cactus-test-plugin-ledger-connector-ethereum`. This allows interacting
    with most recent geth nodes.
- Refactor all ethereum tests. Most of the test cases were duplicated multiple times
    (between different quorum ledger versions test and deployment methods). I've removed all this
    duplication while maintaining similar level of test coverage.
    New tests use Geth test ledger instead of Quorum one.
- Add web3js type conversions methods to minimize impact of poor dynamic typing
    in this early release of 4.X.
- Update API. In 4.X all numeric responses has been converted to BigNum.
    To keep up with this some fields has been changed to string instead of number when necessary.
    Add some missing fields as well.
- Add `estimateMaxFeePerGas` method for estimating current transaction cost.
- Fix invalid `runTransact` response type.
- Add test script for checking integration with Alchemy that must be executed manually
    (it's excluded from CI at the moment) - `geth-alchemy-integration-manual-check.test`.
    Instructions on how to run it has been added to package README.

Future improvements:
- Support London fork gas fees (i.e. EIP-1559)
- Refactor API to allow future extensions.
- Fix several TODO items in this connector.

Closes: hyperledger#2580

Depends on hyperledger#2535
Depends on hyperledger#2578

Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH committed Aug 16, 2023
1 parent 85d8a24 commit d670022
Show file tree
Hide file tree
Showing 44 changed files with 1,840 additions and 6,139 deletions.
11 changes: 0 additions & 11 deletions .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ files:
- ./packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v2.3.0-deploy-contract-from-json-json-object.test.ts
- ./packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/openapi/openapi-validation.test.ts
- ./packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v21.4.1-invoke-contract-json-object.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v2.3.0-invoke-contract-json-object-endpoints.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v21.4.1-invoke-contract-json-object-endpoints.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v21.4.1-deploy-contract-from-json-json-object-endpoints.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v2.3.0-deploy-contract-from-json-json-object-endpoints.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/openapi/openapi-validation-no-keychain.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v2.3.0-invoke-contract-json-object.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v2.3.0-deploy-contract-from-json.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v21.4.1-deploy-contract-from-json-json-object.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v2.3.0-deploy-contract-from-json-json-object.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/openapi/openapi-validation.test.ts
- ./packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/plugin-ledger-connector-ethereum/deploy-contract/v21.4.1-invoke-contract-json-object.test.ts
- ./extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/counterparty-htlc-endpoint.test.ts
- ./extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/own-htlc-endpoint.test.ts
- ./extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/withdraw-counterparty-endpoint.test.ts
Expand Down
12 changes: 1 addition & 11 deletions jest.config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/cactus-cmd-api-server/src/main/typescript/api-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ export class ApiServer {
const corsMiddleware = this.createCorsMiddleware(allowedDomains);
app.use(corsMiddleware);
app.use(bodyParser.json({ limit: "50mb" }));
// Add custom replacer to handle bigint responses correctly
app.set("json replacer", this.stringifyBigIntReplacer);

const authzFactoryOptions = { apiServerOptions, pluginRegistry, logLevel };
const authzFactory = new AuthorizerFactory(authzFactoryOptions);
Expand Down Expand Up @@ -781,4 +783,18 @@ export class ApiServer {
};
return cors(corsOptionsDelegate);
}

/**
* `JSON.stringify` replacer function to handle BigInt.
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
*/
private stringifyBigIntReplacer(
_key: string,
value: bigint | unknown,
): string | unknown {
if (typeof value === "bigint") {
return value.toString();
}
return value;
}
}
Loading

0 comments on commit d670022

Please sign in to comment.