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

Allow the Ethereum connector to use an already deployed contract #1497

Open
Tracked by #1584 ...
mkrielza opened this issue May 15, 2023 · 2 comments
Open
Tracked by #1584 ...

Allow the Ethereum connector to use an already deployed contract #1497

mkrielza opened this issue May 15, 2023 · 2 comments
Labels
component/ethereum Related to the Ethereum adapter enhancement New feature or request help wanted Extra attention is needed

Comments

@mkrielza
Copy link

Please share the technical limitation of Caliper that you encountered.

Running benchmarks against an already deployed contract was not possible without changing the Ethereum connector.

Please detail your feature idea that could alleviate the limitation.

Allow for the case where no smart contracts need to be deployed by adding a contract address to the network configuration file.

Please share some details about your use case if possible, and how the new feature would make Caliper a better performance benchmarking framework.

It would allow the Ethereum connector to use an already deployed contract when running a benchmark.

Please share any suggestions about the new feature's code/configuration API (using formatted YAML segments or pseudo-code).

diff --git a/packages/caliper-ethereum/lib/ethereum-connector.js b/packages/caliper-ethereum/lib/ethereum-connector.js
--- a/packages/caliper-ethereum/lib/ethereum-connector.js	(revision 943ab2a22872639f39ccb36f8baf94b2863e21c6)
+++ b/packages/caliper-ethereum/lib/ethereum-connector.js	(date 1684132327195)
@@ -114,24 +114,30 @@
             }
             this.ethereumConfig.contracts[key].abi = contractData.abi;
-            promises.push(new Promise(async function(resolve, reject) {
-                let contractInstance;
-                try {
-                    if (privacy) {
-                        contractInstance = await self.deployPrivateContract(contractData, privacy);
-                        logger.info(`Deployed private contract ${contractData.name} at ${contractInstance.options.address}`);
-                    } else {
-                        contractInstance = await self.deployContract(contractData);
-                        logger.info(`Deployed contract ${contractData.name} at ${contractInstance.options.address}`);
-                    }
-                } catch (err) {
-                    reject(err);
-                }
-                self.ethereumConfig.contracts[key].address = contractInstance.options.address;
-                self.ethereumConfig.contracts[key].gas = contractGas;
-                self.ethereumConfig.contracts[key].estimateGas = estimateGas;
-                resolve(contractInstance);
-            }));
+            if (contract.address) {
+                self.ethereumConfig.contracts[key].address = contract.address;
+                self.ethereumConfig.contracts[key].gas = contractGas;
+                self.ethereumConfig.contracts[key].estimateGas = estimateGas;
+            } else {
+                promises.push(new Promise(async function (resolve, reject) {
+                    let contractInstance;
+                    try {
+                        if (privacy) {
+                            contractInstance = await self.deployPrivateContract(contractData, privacy);
+                            logger.info(`Deployed private contract ${contractData.name} at ${contractInstance.options.address}`);
+                        } else {
+                            contractInstance = await self.deployContract(contractData);
+                            logger.info(`Deployed contract ${contractData.name} at ${contractInstance.options.address}`);
+                        }
+                    } catch (err) {
+                        reject(err);
+                    }
+                    self.ethereumConfig.contracts[key].address = contractInstance.options.address;
+                    self.ethereumConfig.contracts[key].gas = contractGas;
+                    self.ethereumConfig.contracts[key].estimateGas = estimateGas;
+                    resolve(contractInstance);
+                }));
+            }
         }
         return Promise.all(promises);
     }
@davidkel
Copy link
Contributor

davidkel commented Jun 1, 2024

The solution here is to run caliper but ensure it skips the install phase, you can do this by either skipping the phase or only running a specific phase (Caliper has 5 phases which admittedly are poorly documented). To skip the install phase and thus work with an already deployed contract use the --caliper-flow-skip-install option when launching caliper.

@davidkel
Copy link
Contributor

davidkel commented Jun 2, 2024

see #1589 for more details on skipping install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ethereum Related to the Ethereum adapter enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants