From fdce6b3222fbec1c0f05db41dd5b93fbc8a8939d Mon Sep 17 00:00:00 2001 From: aldousalvarez Date: Mon, 29 Jul 2024 15:23:01 +0800 Subject: [PATCH] ci(connector-xdai): fix docker rate limit issues with openethereum image pull Primary Changes ---------------- 1. Migrated all the xdai connector tests to besu ledger images that is being pulled from ghcr Fixes #3413 Signed-off-by: aldousalvarez --- ...ontract-from-json-xdai-json-object.test.ts | 33 ++++++++------- .../deploy-contract-from-json-xdai.test.ts | 32 ++++++++------ .../invoke-contract-xdai-json-object.test.ts | 34 ++++++++------- .../integration/invoke-contract-xdai.test.ts | 42 ++++++++++--------- 4 files changed, 77 insertions(+), 64 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts index d9122a7e2b..34647cf767 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts @@ -11,9 +11,7 @@ import { } from "../../../main/typescript/public-api"; import { Containers, - K_DEV_WHALE_ACCOUNT_PRIVATE_KEY, - K_DEV_WHALE_ACCOUNT_PUBLIC_KEY, - OpenEthereumTestLedger, + BesuTestLedger, pruneDockerAllIfGithubAction, } from "@hyperledger/cactus-test-tooling"; import { @@ -45,8 +43,16 @@ test(testCase, async (t: Test) => { await Containers.logDiagnostics({ logLevel }); }); - const ledger = new OpenEthereumTestLedger({ logLevel }); - + const ledger = new BesuTestLedger({ logLevel }); + const containerImageVersion = "2021-08-24--feat-1244"; + const containerImageName = + "ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one"; + const besuOptions = { containerImageName, containerImageVersion }; + const besuTestLedger = new BesuTestLedger(besuOptions); + const besuKeyPair = { + privateKey: besuTestLedger.getGenesisAccountPrivKey(), + }; + const firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); test.onFinish(async () => { await ledger.stop(); await ledger.destroy(); @@ -56,9 +62,6 @@ test(testCase, async (t: Test) => { const rpcApiHttpHost = await ledger.getRpcApiHttpHost(); - const whalePubKey = K_DEV_WHALE_ACCOUNT_PUBLIC_KEY; - const whalePrivKey = K_DEV_WHALE_ACCOUNT_PRIVATE_KEY; - const web3 = new Web3(rpcApiHttpHost); const testEthAccount = web3.eth.accounts.create(uuidv4()); @@ -92,12 +95,12 @@ test(testCase, async (t: Test) => { await connector.transact({ web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, transactionConfig: { - from: whalePubKey, + from: firstHighNetWorthAccount, to: testEthAccount.address, value: 10e9, gas: 1000000, @@ -118,8 +121,8 @@ test(testCase, async (t: Test) => { test("deploys contract via .json file", async (t2: Test) => { const deployOut = await connector.deployContractJsonObject({ web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, gas: 1000000, @@ -147,8 +150,8 @@ test(testCase, async (t: Test) => { methodName: "sayHello", params: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, gas: 1000000, diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts index 5e2916df6a..b2ef06081c 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai.test.ts @@ -14,9 +14,7 @@ import { } from "../../../main/typescript/public-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { - K_DEV_WHALE_ACCOUNT_PRIVATE_KEY, - K_DEV_WHALE_ACCOUNT_PUBLIC_KEY, - OpenEthereumTestLedger, + BesuTestLedger, pruneDockerAllIfGithubAction, } from "@hyperledger/cactus-test-tooling"; import { @@ -36,11 +34,17 @@ import { K_CACTUS_XDAI_TOTAL_TX_COUNT } from "../../../main/typescript/prometheu const testCase = "deploys contract via .json file"; describe(testCase, () => { const logLevel: LogLevelDesc = "TRACE"; - const ledger = new OpenEthereumTestLedger({ logLevel }); + const ledger = new BesuTestLedger({ logLevel }); + const containerImageVersion = "2021-08-24--feat-1244"; + const containerImageName = + "ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one"; + const besuOptions = { containerImageName, containerImageVersion }; + const besuTestLedger = new BesuTestLedger(besuOptions); + const besuKeyPair = { + privateKey: besuTestLedger.getGenesisAccountPrivKey(), + }; const contractName = "HelloWorld"; const expressApp = express(); - const whalePubKey = K_DEV_WHALE_ACCOUNT_PUBLIC_KEY; - const whalePrivKey = K_DEV_WHALE_ACCOUNT_PRIVATE_KEY; expressApp.use(bodyParser.json({ limit: "250mb" })); const server = http.createServer(expressApp); let addressInfo, @@ -52,6 +56,7 @@ describe(testCase, () => { apiHost: string, web3: Web3, factory: PluginFactoryLedgerConnector, + firstHighNetWorthAccount: string, testEthAccount: Account, keychainEntryKey: string, keychainEntryValue: string, @@ -60,6 +65,7 @@ describe(testCase, () => { apiClient: XdaiApi; beforeAll(async () => { + firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); const pruning = pruneDockerAllIfGithubAction({ logLevel }); await expect(pruning).resolves.toBeTruthy(); }); @@ -125,12 +131,12 @@ describe(testCase, () => { await connector.transact({ web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, transactionConfig: { - from: whalePubKey, + from: firstHighNetWorthAccount, to: testEthAccount.address, value: 10e9, gas: 1000000, @@ -154,8 +160,8 @@ describe(testCase, () => { // contractAbi: HelloWorldContractJson.abi, constructorArgs: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, gas: 1000000, @@ -174,8 +180,8 @@ describe(testCase, () => { methodName: "sayHello", params: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, }); diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts index 46d8917aa1..e9395ad486 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts @@ -9,11 +9,7 @@ import { ReceiptType, } from "../../../main/typescript/public-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -import { - K_DEV_WHALE_ACCOUNT_PRIVATE_KEY, - K_DEV_WHALE_ACCOUNT_PUBLIC_KEY, - OpenEthereumTestLedger, -} from "@hyperledger/cactus-test-tooling"; +import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; import { LogLevelDesc } from "@hyperledger/cactus-common"; import HelloWorldContractJson from "../../solidity/hello-world-contract/HelloWorld.json"; import Web3 from "web3"; @@ -21,7 +17,16 @@ import { PluginImportType } from "@hyperledger/cactus-core-api"; test("deploys contract via .json file", async (t: Test) => { const logLevel: LogLevelDesc = "TRACE"; - const xdaiTestLedger = new OpenEthereumTestLedger({}); + const xdaiTestLedger = new BesuTestLedger({}); + const containerImageVersion = "2021-08-24--feat-1244"; + const containerImageName = + "ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one"; + const besuOptions = { containerImageName, containerImageVersion }; + const besuTestLedger = new BesuTestLedger(besuOptions); + const besuKeyPair = { + privateKey: besuTestLedger.getGenesisAccountPrivKey(), + }; + const firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); await xdaiTestLedger.start(); test.onFinish(async () => { @@ -31,9 +36,6 @@ test("deploys contract via .json file", async (t: Test) => { const rpcApiHttpHost = await xdaiTestLedger.getRpcApiHttpHost(); - const whalePubKey = K_DEV_WHALE_ACCOUNT_PUBLIC_KEY; - const whalePrivKey = K_DEV_WHALE_ACCOUNT_PRIVATE_KEY; - const web3 = new Web3(rpcApiHttpHost); const testEthAccount = web3.eth.accounts.create(uuidv4()); @@ -63,8 +65,8 @@ test("deploys contract via .json file", async (t: Test) => { await connector.transact({ web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, consistencyStrategy: { @@ -72,7 +74,7 @@ test("deploys contract via .json file", async (t: Test) => { receiptType: ReceiptType.NodeTxPoolAck, }, transactionConfig: { - from: whalePubKey, + from: firstHighNetWorthAccount, to: testEthAccount.address, value: 10e9, gas: 1000000, @@ -89,8 +91,8 @@ test("deploys contract via .json file", async (t: Test) => { const deployOut = await connector.deployContractJsonObject({ constructorArgs: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, gas: 1000000, @@ -118,8 +120,8 @@ test("deploys contract via .json file", async (t: Test) => { methodName: "sayHello", params: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, contractJSON: HelloWorldContractJson, diff --git a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts index a426c9a00f..c4446d3d3b 100644 --- a/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts +++ b/packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai.test.ts @@ -11,24 +11,27 @@ import { ReceiptType, } from "../../../main/typescript/public-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -import { - K_DEV_WHALE_ACCOUNT_PRIVATE_KEY, - K_DEV_WHALE_ACCOUNT_PUBLIC_KEY, - OpenEthereumTestLedger, -} from "@hyperledger/cactus-test-tooling"; +import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; import { LogLevelDesc } from "@hyperledger/cactus-common"; import HelloWorldContractJson from "../../solidity/hello-world-contract/HelloWorld.json"; import Web3 from "web3"; import { PluginImportType } from "@hyperledger/cactus-core-api"; const logLevel: LogLevelDesc = "TRACE"; -let xdaiTestLedger: OpenEthereumTestLedger; +let xdaiTestLedger: BesuTestLedger; const testCase = "Xdai Ledger Connector Plugin"; describe(testCase, () => { + const containerImageVersion = "2021-08-24--feat-1244"; + const containerImageName = + "ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one"; + const besuOptions = { containerImageName, containerImageVersion }; + const besuTestLedger = new BesuTestLedger(besuOptions); + const besuKeyPair = { + privateKey: besuTestLedger.getGenesisAccountPrivKey(), + }; + let firstHighNetWorthAccount: string; let contractAddress: string; const contractName = "HelloWorld"; - const whalePubKey = K_DEV_WHALE_ACCOUNT_PUBLIC_KEY; - const whalePrivKey = K_DEV_WHALE_ACCOUNT_PRIVATE_KEY; let keychainPlugin: PluginKeychainMemory; let connector: PluginLedgerConnectorXdai; let web3: Web3; @@ -37,7 +40,7 @@ describe(testCase, () => { let keychainEntryValue: string, rpcApiHttpHost: string; beforeAll(async () => { - xdaiTestLedger = new OpenEthereumTestLedger({}); + xdaiTestLedger = new BesuTestLedger({}); }); afterAll(async () => { @@ -46,6 +49,7 @@ describe(testCase, () => { }); beforeAll(async () => { await xdaiTestLedger.start(); + firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); rpcApiHttpHost = await xdaiTestLedger.getRpcApiHttpHost(); expect(rpcApiHttpHost).toBeString(); @@ -82,8 +86,8 @@ describe(testCase, () => { await connector.transact({ web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, consistencyStrategy: { @@ -91,7 +95,7 @@ describe(testCase, () => { receiptType: ReceiptType.NodeTxPoolAck, }, transactionConfig: { - from: whalePubKey, + from: firstHighNetWorthAccount, to: testEthAccount.address, value: 10e9, gas: 1000000, @@ -110,8 +114,8 @@ describe(testCase, () => { // contractAbi: HelloWorldContractJson.abi, constructorArgs: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, // bytecode: HelloWorldContractJson.bytecode, @@ -131,8 +135,8 @@ describe(testCase, () => { methodName: "sayHello", params: [], web3SigningCredential: { - ethAccount: whalePubKey, - secret: whalePrivKey, + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PrivateKeyHex, }, }); @@ -205,7 +209,7 @@ describe(testCase, () => { }); fail("invalid nonce should have thrown"); } catch (error: any) { - expect(error.message).toContain("Transaction nonce is too low."); + expect(error.message).toContain("Nonce too low"); } const { callOutput: getNameOut } = await connector.invokeContract({ contractName, @@ -303,9 +307,7 @@ describe(testCase, () => { }); fail("invalid nonce should have thrown"); } catch (error: any) { - expect(error.message).toContain( - "Transaction with the same hash was already imported", - ); + expect(error.message).toContain("Nonce too low"); } const { callOutput: getNameOut } = await connector.invokeContract({ contractName,