Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
cr fix - move contract codes to contractsapi
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed May 17, 2023
1 parent 6e075ab commit 99efd02
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 90 deletions.
81 changes: 0 additions & 81 deletions benchmark/contract_codes.go

This file was deleted.

6 changes: 1 addition & 5 deletions benchmark/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ func deployContractOnRootAndChild(
childTxRelayer txrelayer.TxRelayer,
rootTxRelayer txrelayer.TxRelayer,
sender ethgo.Key,
byteCodeString string) (ethgo.Address, ethgo.Address) {
byteCode []byte) (ethgo.Address, ethgo.Address) {
b.Helper()

// bytecode from string
byteCode, err := hex.DecodeString(byteCodeString)
require.NoError(b, err)

// deploy contract on the child chain
contractChildAddr := deployContract(b, childTxRelayer, sender, byteCode)

Expand Down
9 changes: 5 additions & 4 deletions benchmark/root_child_send_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"
"testing"

"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/e2e-polybft/framework"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -107,13 +108,13 @@ func RootChildSendTxSetUp(b *testing.B) ([]TxTestCase, func()) {

// deploy contracts
singleContChildAddr, singleContRootAddr := deployContractOnRootAndChild(b, childTxRelayer, rootTxRelayer,
sender, singleContByteCode)
sender, contractsapi.TestBenchmarkSingle.Bytecode)
multiAContChildAddr, multiAContRootAddr := deployContractOnRootAndChild(b, childTxRelayer, rootTxRelayer,
sender, multiContAByteCode)
sender, contractsapi.TestBenchmarkA.Bytecode)
multiBContChildAddr, multiBContRootAddr := deployContractOnRootAndChild(b, childTxRelayer, rootTxRelayer,
sender, multiContBByteCode)
sender, contractsapi.TestBenchmarkB.Bytecode)
multiCContChildAddr, multiCContRootAddr := deployContractOnRootAndChild(b, childTxRelayer, rootTxRelayer,
sender, multiContCByteCode)
sender, contractsapi.TestBenchmarkC.Bytecode)

// set callee contract addresses for multi call contracts (A->B->C)
// set B contract address in A contract
Expand Down
24 changes: 24 additions & 0 deletions consensus/polybft/contractsapi/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ var (
RootERC20 *artifact.Artifact
TestSimple *artifact.Artifact
TestRewardToken *artifact.Artifact
TestBenchmarkA *artifact.Artifact
TestBenchmarkB *artifact.Artifact
TestBenchmarkC *artifact.Artifact
TestBenchmarkSingle *artifact.Artifact
)

func init() {
Expand Down Expand Up @@ -202,6 +206,26 @@ func init() {
log.Fatal(err)
}

TestBenchmarkA, err = artifact.DecodeArtifact(readTestContractContent("TestBenchmarkA.json"))
if err != nil {
log.Fatal(err)
}

TestBenchmarkB, err = artifact.DecodeArtifact(readTestContractContent("TestBenchmarkB.json"))
if err != nil {
log.Fatal(err)
}

TestBenchmarkC, err = artifact.DecodeArtifact(readTestContractContent("TestBenchmarkC.json"))
if err != nil {
log.Fatal(err)
}

TestBenchmarkSingle, err = artifact.DecodeArtifact(readTestContractContent("TestBenchmarkSingle.json"))
if err != nil {
log.Fatal(err)
}

CustomSupernetManager, err = artifact.DecodeArtifact([]byte(CustomSupernetManagerArtifact))
if err != nil {
log.Fatal(err)
Expand Down
24 changes: 24 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/ITestBenchmarkB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "ITestBenchmarkB",
"sourceName": "contracts/test/TestBenchmarkA.sol",
"abi": [
{
"inputs": [],
"name": "fnB",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
24 changes: 24 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/ITestBenchmarkC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "ITestBenchmarkC",
"sourceName": "contracts/test/TestBenchmarkB.sol",
"abi": [
{
"inputs": [],
"name": "fnC1",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x",
"deployedBytecode": "0x",
"linkReferences": {},
"deployedLinkReferences": {}
}
37 changes: 37 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/TestBenchmarkA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "TestBenchmarkA",
"sourceName": "contracts/test/TestBenchmarkA.sol",
"abi": [
{
"inputs": [],
"name": "fnA",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_contract",
"type": "address"
}
],
"name": "setContractAddr",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061017b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063286d2e3a1461003b57806368685ad31461006d575b600080fd5b61006b6100493660046100fc565b600080546001600160a01b0319166001600160a01b0392909216919091179055565b005b610075610087565b60405190815260200160405180910390f35b6000805460408051636cde00cd60e01b8152905183926001600160a01b031691636cde00cd916004808301926020929190829003018187875af11580156100d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100f6919061012c565b92915050565b60006020828403121561010e57600080fd5b81356001600160a01b038116811461012557600080fd5b9392505050565b60006020828403121561013e57600080fd5b505191905056fea2646970667358221220a8ce85649b9a1ab453ecb852ac36c64f7be380547a5cf2faf83ffdbb59b6424464736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063286d2e3a1461003b57806368685ad31461006d575b600080fd5b61006b6100493660046100fc565b600080546001600160a01b0319166001600160a01b0392909216919091179055565b005b610075610087565b60405190815260200160405180910390f35b6000805460408051636cde00cd60e01b8152905183926001600160a01b031691636cde00cd916004808301926020929190829003018187875af11580156100d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100f6919061012c565b92915050565b60006020828403121561010e57600080fd5b81356001600160a01b038116811461012557600080fd5b9392505050565b60006020828403121561013e57600080fd5b505191905056fea2646970667358221220a8ce85649b9a1ab453ecb852ac36c64f7be380547a5cf2faf83ffdbb59b6424464736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
18 changes: 18 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/TestBenchmarkA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface ITestBenchmarkB {
function fnB() external returns (uint256);
}
contract TestBenchmarkA {
address contractAddr;

function setContractAddr(address _contract) public {
contractAddr = _contract;
}

function fnA() public returns (uint256) {
uint256 valB = ITestBenchmarkB(contractAddr).fnB();
return valB;
}
}
50 changes: 50 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/TestBenchmarkB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "TestBenchmarkB",
"sourceName": "contracts/test/TestBenchmarkB.sol",
"abi": [
{
"inputs": [],
"name": "fnB",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_contract",
"type": "address"
}
],
"name": "setContractAddr",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "valB",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506101db806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063286d2e3a146100465780636cde00cd14610078578063735b7e6f14610092575b600080fd5b610076610054366004610135565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b005b61008061009b565b60405190815260200160405180910390f35b61008060005481565b600080600160009054906101000a90046001600160a01b03166001600160a01b03166349ec07186040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101179190610165565b90508060008082825461012a919061017e565b909155509092915050565b60006020828403121561014757600080fd5b81356001600160a01b038116811461015e57600080fd5b9392505050565b60006020828403121561017757600080fd5b5051919050565b8082018082111561019f57634e487b7160e01b600052601160045260246000fd5b9291505056fea26469706673582212209f01d2971a8238a2a1c208a8dde49ecc84579475e54782314375cb36d1bf60ea64736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063286d2e3a146100465780636cde00cd14610078578063735b7e6f14610092575b600080fd5b610076610054366004610135565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b005b61008061009b565b60405190815260200160405180910390f35b61008060005481565b600080600160009054906101000a90046001600160a01b03166001600160a01b03166349ec07186040518163ffffffff1660e01b81526004016020604051808303816000875af11580156100f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101179190610165565b90508060008082825461012a919061017e565b909155509092915050565b60006020828403121561014757600080fd5b81356001600160a01b038116811461015e57600080fd5b9392505050565b60006020828403121561017757600080fd5b5051919050565b8082018082111561019f57634e487b7160e01b600052601160045260246000fd5b9291505056fea26469706673582212209f01d2971a8238a2a1c208a8dde49ecc84579475e54782314375cb36d1bf60ea64736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
20 changes: 20 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/TestBenchmarkB.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface ITestBenchmarkC {
function fnC1() external returns (uint256);
}
contract TestBenchmarkB {
uint256 public valB;
address contractAddr;

function setContractAddr(address _contract) public {
contractAddr = _contract;
}

function fnB() external returns (uint256) {
uint256 valC = ITestBenchmarkC(contractAddr).fnC1();
valB += valC;
return valC;
}
}
50 changes: 50 additions & 0 deletions consensus/polybft/contractsapi/test-contracts/TestBenchmarkC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "TestBenchmarkC",
"sourceName": "contracts/test/TestBenchmarkC.sol",
"abi": [
{
"inputs": [],
"name": "fnC1",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "fnC2",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "valC",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5061015f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80631990ceb9146100465780633b3cf4e31461006057806349ec071814610069575b600080fd5b61004e610071565b60405190815260200160405180910390f35b61004e60005481565b61004e6100b9565b600060644244604051602001610091929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c6100b491906100e0565b905090565b6000806100c4610071565b60008054919250806100d583610102565b909155509092915050565b6000826100fd57634e487b7160e01b600052601260045260246000fd5b500690565b60006001820161012257634e487b7160e01b600052601160045260246000fd5b506001019056fea264697066735822122092ffbbf005793faaa839fdfd4e894697301342a305e3e8734927815308198d7964736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c80631990ceb9146100465780633b3cf4e31461006057806349ec071814610069575b600080fd5b61004e610071565b60405190815260200160405180910390f35b61004e60005481565b61004e6100b9565b600060644244604051602001610091929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c6100b491906100e0565b905090565b6000806100c4610071565b60008054919250806100d583610102565b909155509092915050565b6000826100fd57634e487b7160e01b600052601260045260246000fd5b500690565b60006001820161012257634e487b7160e01b600052601160045260246000fd5b506001019056fea264697066735822122092ffbbf005793faaa839fdfd4e894697301342a305e3e8734927815308198d7964736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Loading

0 comments on commit 99efd02

Please sign in to comment.