Motivation: The current testing process in OrbiterSDK for contracts involves extensive boilerplate code, creating inefficiencies and complexities. This includes manually setting up blockchain elements (DB, State, P2P, rdPoS, State, Options), building transactions and contract call data, processing blocks, decoding view function calls, and deploying contracts. The provided ERC20 Testing example illustrates the cumbersome nature of these tasks, highlighting the need for a more streamlined approach.
Objective: Develop a "ContractTestSuite" class to automate and simplify the testing process. This suite should handle the creation and interaction with contracts, leveraging templated functions for tasks such as creating new contracts, calling non-view and view contract functions, and conducting blockchain consultations. It should also support transactions from accounts other than the chain owner. The goal is to minimize the manual coding required for smart contract testing, making it as user-friendly as HardHat. Introduce syntax simplifications, as shown in the ERC20 test case example. This new approach reduces code complexity and improves readability, enabling developers to focus more on testing logic rather than setup procedures.
TEST_CASE("ERC2O Class", "[contract][erc20]") {
SECTION("ERC20 Class Transfer") {
Address erc20Address;
{
auto targetOfTxs = Address::randomAddress(); // randomAddress doesn't exist, please assume it does.
auto TestEngine = std::make_unique<ContractTestSuite>("dbPath");
erc20Address = TestEngine->createNewContract<ERC20>("TestToken","TSTT", 18, uint256_t("1000000000000000000");
uint256_t erc20Balance = TestEngine->callViewFunction(erc20Address, &ERC20::balanceOf, TestEngine->chainOwnerAddress());
/// When calling a function use the chain owner address as the transaction sender by default
Hash sendToTargetOfTxs = TestEngine->callFunction(&ERC20::transfer, targetOfTxs, uint256_t("10000000"));
}
Success Criteria: The implementation should significantly reduce the amount of code required for unit testing smart contracts. It should be as intuitive and efficient as existing solutions like HardHat, ensuring ease of use for developers.
Dependencies: None identified.
Risks and Mitigations: One potential risk is the handling of the blockchain and the default use of the owner's private key. It's essential to provide flexibility for using different accounts and ensure secure key management. Additionally, thorough documentation and clear guidelines will be crucial for smoothly integrating this suite into existing workflows.
Resource Allocation: This feature focuses exclusively on enhancing contract unit testing. It necessitates updating existing tests to align with the new Test Suite model, which should be planned to minimize disruption to ongoing development.
Implementing "ContractTestSuite" will modernize and simplify the contract testing process in OrbiterSDK, aligning it with best practices in blockchain development and making it more accessible to a broader range of developers.
Success Criteria: The implementation should significantly reduce the amount of code required for unit testing smart contracts. It should be as intuitive and efficient as existing solutions like HardHat, ensuring ease of use for developers.
Dependencies: None identified.
Risks and Mitigations: One potential risk is the handling of the blockchain and the default use of the owner's private key. It's essential to provide flexibility for using different accounts and ensure secure key management. Additionally, thorough documentation and clear guidelines will be crucial for smoothly integrating this suite into existing workflows.
Resource Allocation: This feature focuses exclusively on enhancing contract unit testing. It necessitates updating existing tests to align with the new Test Suite model, which should be planned to minimize disruption to ongoing development.
Implementing "ContractTestSuite" will modernize and simplify the contract testing process in OrbiterSDK, aligning it with best practices in blockchain development and making it more accessible to a broader range of developers.