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

Update ethereum fn call setting weight limit and proof size weight cost #777

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions e2e-tests/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const LOCAL_NODE_URL = "http://127.0.0.1:9999";
// Chain config
export const CHAIN_ID = 667;
export const GAS_PRICE = "0x3B9ACA00";
export const ETH_BLOCK_GAS_LIMIT = 15000000; // The same configuration as runtime
export const GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - 10000000; // TODO remove subtraction

// Accounts
export const FAITH = "0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d";
Expand Down
5 changes: 2 additions & 3 deletions e2e-tests/tests/test-create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Contract from "web3-eth-contract";
import {
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
EVOLUTION_COLLECTION_FACTORY_ABI,
GAS_LIMIT,
GAS_PRICE,
FAITH,
FAITH_PRIVATE_KEY,
Expand All @@ -27,7 +26,6 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
{
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
}
);
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
Expand All @@ -42,9 +40,10 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
});

step("when collection is created event is emitted", async function () {
const estimatedGas = await contract.methods.createCollection(FAITH).estimateGas();
const result = await contract.methods.createCollection(FAITH).send({
from: FAITH,
gas: GAS_LIMIT,
gas: estimatedGas,
gasPrice: GAS_PRICE,
});
expect(result.status).to.be.eq(true);
Expand Down
45 changes: 24 additions & 21 deletions e2e-tests/tests/test-evolution.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { createCollection, describeWithExistingNode, slotAndOwnerToTokenId } from "./util";
import {
addressToCollectionId,
createCollection,
describeWithExistingNode,
extractRevertReason,
slotAndOwnerToTokenId,
} from "./util";
import {
GAS_LIMIT,
FAITH,
SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI,
SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI,
SELECTOR_LOG_OWNERSHIP_TRANSFERRED,
SELECTOR_LOG_PUBLIC_MINTING_ENABLED,
SELECTOR_LOG_PUBLIC_MINTING_DISABLED,
ALITH,
ALITH_PRIVATE_KEY,
} from "./config";
import { expect } from "chai";
import Contract from "web3-eth-contract";
Expand Down Expand Up @@ -47,9 +36,10 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => {
const tokenURI = "https://example.com";

let nonce = await context.web3.eth.getTransactionCount(FAITH);
const estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const result = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: GAS_LIMIT, nonce: nonce++ });
.send({ from: FAITH, gas: estimatedGas, nonce: nonce++ });
expect(result.status).to.be.eq(true);

const tokenId = result.events.MintedWithExternalURI.returnValues._tokenId;
Expand All @@ -72,9 +62,10 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => {
const to = FAITH;
const tokenURI = "https://example.com";

const estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const result = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(result.status).to.be.eq(true);

expect(Object.keys(result.events).length).to.be.eq(1);
Expand Down Expand Up @@ -108,14 +99,18 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => {
const tokenId = slotAndOwnerToTokenId(slot, to);
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10);

var estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const mintingResult = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(mintingResult.status).to.be.eq(true);

estimatedGas = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.estimateGas();
const evolvingResult = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(evolvingResult.status).to.be.eq(true);

const got = await collectionContract.methods.tokenURI(tokenIdDecimal).call();
Expand All @@ -130,14 +125,18 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => {
const tokenId = slotAndOwnerToTokenId(slot, to);
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10);

var estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const mintingResult = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(mintingResult.status).to.be.eq(true);

estimatedGas = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.estimateGas();
const evolvingResult = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(evolvingResult.status).to.be.eq(true);

expect(Object.keys(evolvingResult.events).length).to.be.eq(1);
Expand Down Expand Up @@ -171,9 +170,10 @@ describeWithExistingNode("Frontier RPC (Transfer Ownership)", (context) => {
const newOwner = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac";

expect(await collectionContract.methods.owner().call()).to.be.eq(FAITH);
const estimatedGas = await collectionContract.methods.transferOwnership(newOwner).estimateGas();
const tranferringResult = await collectionContract.methods
.transferOwnership(newOwner)
.send({ from: FAITH, gas: GAS_LIMIT });
.send({ from: FAITH, gas: estimatedGas });
expect(tranferringResult.status).to.be.eq(true);
expect(await collectionContract.methods.owner().call()).to.be.eq(newOwner);

Expand All @@ -198,10 +198,13 @@ describeWithExistingNode("Frontier RPC (Transfer Ownership)", (context) => {
expect(tranferringResult.events.OwnershipTransferred.raw.data).to.be.eq("0x");

try {
await collectionContract.methods.transferOwnership(FAITH).send({ from: FAITH, gas: GAS_LIMIT });
const estimatedGas = await collectionContract.methods.transferOwnership(FAITH).estimateGas();
await collectionContract.methods.transferOwnership(FAITH).send({ from: FAITH, gas: estimatedGas });
expect.fail("Expected error was not thrown"); // Ensure an error is thrown
} catch (error) {
expect(await extractRevertReason(context, error.receipt.transactionHash)).to.eq("NoPermission");
expect(error.message).to.eq(
"Returned error: VM Exception while processing transaction: revert NoPermission"
);
}
});
});
5 changes: 2 additions & 3 deletions e2e-tests/tests/test-staking.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { describeWithExistingNode } from "./util";
import {
GAS_LIMIT,
ALITH,
STAKING_ABI,
STAKING_CONTRACT_ADDRESS,
GAS_PRICE,
UNIT,
FAITH_PRIVATE_KEY,
FAITH,
Expand Down Expand Up @@ -57,9 +55,10 @@ describeWithExistingNode("Frontier RPC (Staking)", (context) => {
expect(await contract.methods.isDelegator(BALTATHAR).call()).to.be.eq(false);
let nonce = await context.web3.eth.getTransactionCount(BALTATHAR);
const gasPrice = (await context.web3.eth.getGasPrice()) + 1; // if we don't add +1 tx never gets included in the block
const estimatedGas = await contract.methods.delegate(FAITH, BigInt(1000) * UNIT, 0, 0).estimateGas();
const result = await contract.methods
.delegate(FAITH, BigInt(1000) * UNIT, 0, 0)
.send({ from: BALTATHAR, gas: GAS_LIMIT, gasPrice, nonce: nonce++ });
.send({ from: BALTATHAR, gas: estimatedGas, gasPrice, nonce: nonce++ });
expect(result.status).to.be.eq(true);
expect(await contract.methods.isDelegator(BALTATHAR).call()).to.be.eq(true);
});
Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/tests/test-update-extended-token-uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Contract from "web3-eth-contract";
import {
ASSET_METADATA_EXTENDER_ADDRESS,
ASSET_METADATA_EXTENDER_ABI,
GAS_LIMIT,
GAS_PRICE,
FAITH,
FAITH_PRIVATE_KEY,
Expand All @@ -20,7 +19,6 @@ describeWithExistingNode("Frontier RPC (Extend Token URI)", (context) => {
contract = new context.web3.eth.Contract(ASSET_METADATA_EXTENDER_ABI, ASSET_METADATA_EXTENDER_ADDRESS, {
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
});
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
});
Expand All @@ -36,9 +34,10 @@ describeWithExistingNode("Frontier RPC (Extend Token URI)", (context) => {

step("extend should return ok", async function () {
let nonce = await context.web3.eth.getTransactionCount(FAITH);
const estimatedGas = await contract.methods.extendULWithExternalURI(uloc, tokenURI).estimateGas();
extendResult = await contract.methods.extendULWithExternalURI(uloc, tokenURI).send({
from: FAITH,
gas: GAS_LIMIT,
gas: estimatedGas,
gasPrice: GAS_PRICE,
nonce: nonce++,
});
Expand Down Expand Up @@ -94,15 +93,15 @@ describeWithExistingNode("Frontier RPC (Update Extended Token URI)", async (cont
contract = new context.web3.eth.Contract(ASSET_METADATA_EXTENDER_ABI, ASSET_METADATA_EXTENDER_ADDRESS, {
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
});
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);

// we first create an extension to be updated later
let nonce = await context.web3.eth.getTransactionCount(FAITH);
const estimatedGas = await contract.methods.extendULWithExternalURI(uloc, tokenURI).estimateGas();
const createResult = await contract.methods.extendULWithExternalURI(uloc, tokenURI).send({
from: FAITH,
gas: GAS_LIMIT,
gas: estimatedGas,
gasPrice: GAS_PRICE,
nonce: nonce++,
});
Expand All @@ -119,9 +118,10 @@ describeWithExistingNode("Frontier RPC (Update Extended Token URI)", async (cont

step("update extension should return ok", async function () {
let nonce = await context.web3.eth.getTransactionCount(FAITH);
const estimatedGas = await contract.methods.updateExtendedULWithExternalURI(uloc, newTokenURI).estimateGas();
updateExtensionResult = await contract.methods.updateExtendedULWithExternalURI(uloc, newTokenURI).send({
from: FAITH,
gas: GAS_LIMIT,
gas: estimatedGas,
gasPrice: GAS_PRICE,
nonce: nonce++,
});
Expand Down
19 changes: 10 additions & 9 deletions e2e-tests/tests/test-vesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ import Contract from "web3-eth-contract";
import {
VESTING_CONTRACT_ADDRESS,
VESTING_ABI,
GAS_LIMIT,
GAS_PRICE,
FAITH,
FAITH_PRIVATE_KEY,
ALITH,
ALITH_PRIVATE_KEY,
} from "./config";
import { describeWithExistingNode, extractRevertReason } from "./util";
import Web3 from "web3";
import { describeWithExistingNode } from "./util";

describeWithExistingNode("Frontier RPC (Vesting)", (context) => {
let contract: Contract;

before(async function () {
contract = new context.web3.eth.Contract(VESTING_ABI, VESTING_CONTRACT_ADDRESS, {
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
});
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
context.web3.eth.accounts.wallet.add(ALITH_PRIVATE_KEY);
Expand All @@ -34,10 +30,12 @@ describeWithExistingNode("Frontier RPC (Vesting)", (context) => {
it("when there is no vesting do vest reverts", async function () {
try {
let nonce = await context.web3.eth.getTransactionCount(FAITH);
await contract.methods.vest().send({ from: FAITH, gas: GAS_LIMIT, nonce: nonce++ });
const estimatedGas = await contract.methods.vest().estimateGas();
contract.options.from = FAITH;
await contract.methods.vest().send({ from: FAITH, gas: estimatedGas, nonce: nonce++ });
expect.fail("Expected error was not thrown"); // Ensure an error is thrown
} catch (error) {
expect(await extractRevertReason(context, error.receipt.transactionHash)).to.eq("NotVesting");
expect(error.message).to.eq("Returned error: VM Exception while processing transaction: revert NotVesting");
}
});
it("when vesting exists it returns the list", async function () {
Expand All @@ -50,12 +48,15 @@ describeWithExistingNode("Frontier RPC (Vesting)", (context) => {
step("when vesting exists do vest returns ok", async function () {
let nonce = await context.web3.eth.getTransactionCount(ALITH);
contract.options.from = ALITH;
let result = await contract.methods.vest().send({ from: ALITH, gas: GAS_LIMIT, nonce: nonce++ });
const estimatedGas = await contract.methods.vest().estimateGas();
let result = await contract.methods.vest().send({ from: ALITH, gas: estimatedGas, nonce: nonce++ });
expect(result.status).to.be.eq(true);
});
step("when vesting exists do vestOther returns ok", async function () {
let nonce = await context.web3.eth.getTransactionCount(FAITH);
let result = await contract.methods.vestOther(ALITH).send({ from: FAITH, gas: GAS_LIMIT, nonce: nonce++ });
contract.options.from = FAITH;
const estimatedGas = await contract.methods.vestOther(ALITH).estimateGas();
let result = await contract.methods.vestOther(ALITH).send({ from: FAITH, gas: estimatedGas, nonce: nonce++ });
expect(result.status).to.be.eq(true);
});
});
5 changes: 2 additions & 3 deletions e2e-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Web3 from "web3";
import { JsonRpcResponse } from "web3-core-helpers";
import {
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
GAS_LIMIT,
GAS_PRICE,
FAITH,
FAITH_PRIVATE_KEY,
Expand Down Expand Up @@ -87,9 +86,10 @@ export async function createCollection(context: { web3: Web3 }): Promise<Contrac

let nonce = await context.web3.eth.getTransactionCount(FAITH);
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
const estimatedGas = await contract.methods.createCollection(FAITH).estimateGas();
const result = await contract.methods.createCollection(FAITH).send({
from: FAITH,
gas: GAS_LIMIT,
gas: estimatedGas,
gasPrice: GAS_PRICE,
nonce: nonce++,
});
Expand All @@ -101,7 +101,6 @@ export async function createCollection(context: { web3: Web3 }): Promise<Contrac
result.events.NewCollection.returnValues._collectionAddress,
{
from: FAITH,
gas: GAS_LIMIT,
gasPrice: GAS_PRICE,
}
);
Expand Down
Loading
Loading