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

chore: run benchmarking utility in devnet environment #3166

Merged
merged 33 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
02f6067
chore: added devnet config
maschad Sep 13, 2024
3a664c4
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 13, 2024
3f53e84
chore: updated lockfile
maschad Sep 13, 2024
2e38db3
docs: add changeset
maschad Sep 13, 2024
2592c90
chore: use pyth large contract + update test config
maschad Sep 13, 2024
5bd8e74
test: testing with 10 iterations per bench
maschad Sep 16, 2024
466f0b8
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 16, 2024
6a5b867
test: update contract interaction test
maschad Sep 16, 2024
89a2f48
chore: wallet method updates
maschad Sep 17, 2024
12af6da
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 17, 2024
7d2389c
test: add console logs for wallet addresses in CI
maschad Sep 17, 2024
aae74db
test: add more debug logs...
maschad Sep 17, 2024
e510839
test: attempt using static deploy method
maschad Sep 17, 2024
3998316
chore: reduce contract calls for test
maschad Sep 17, 2024
deb5f77
test: removing problematic tests
maschad Sep 17, 2024
d559940
test: only loop local node tests
maschad Sep 18, 2024
ab23f26
test: update cost estimation loop
maschad Sep 18, 2024
03bb4be
test: update contract read calls
maschad Sep 18, 2024
535145d
chore: refactor benchmarking tests
maschad Sep 18, 2024
26f53ef
ci: update workflows
maschad Sep 18, 2024
50aad4c
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 18, 2024
aea62fb
chore: refactoring + cleanup
maschad Sep 19, 2024
386cb73
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 19, 2024
2b3047c
chore: update to large contract factory
maschad Sep 19, 2024
af76ec6
lint: forc formatting
maschad Sep 19, 2024
4fcf577
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 20, 2024
4ad4ce1
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 24, 2024
38920e3
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 25, 2024
c25f012
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 26, 2024
be5f2d3
Merge branch 'master' into mc/test/add-benchmarks-devnet
maschad Sep 27, 2024
be9151d
chore: remove private key
maschad Sep 27, 2024
fc6ab5d
Merge branch 'next' into mc/test/add-benchmarks-devnet
maschad Sep 27, 2024
3aee69e
Merge branch 'next' into mc/test/add-benchmarks-devnet
maschad Oct 1, 2024
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
5 changes: 5 additions & 0 deletions .changeset/ninety-carpets-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@internal/benchmarks": patch
---

chore: run benchmarking utility in devnet environment
27 changes: 27 additions & 0 deletions .github/workflows/bench-devnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Bench Devnet"

on:
push:
branches:
- release/*

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: CI Setup
uses: ./.github/actions/test-setup

- name: Pretest
run: pnpm pretest

- name: Run Node benchmarks
uses: CodSpeedHQ/action@v3
with:
run: pnpm bench:node
token: ${{ secrets.CODSPEED_TOKEN }}
env:
DEVNET_WALLET_PVT_KEY: ${{ secrets.DEVNET_WALLET_PVT_KEY }}
1 change: 1 addition & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Benchmarks

on:
pull_request:
push:
maschad marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion internal/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"license": "Apache-2.0",
"dependencies": {
"fuels": "workspace:*"
"fuels": "workspace:*",
"@internal/utils": "workspace:*"
},
"version": "1.0.3"
}
17 changes: 17 additions & 0 deletions internal/benchmarks/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable import/no-extraneous-dependencies */

import { bench } from 'vitest';

export const isDevnet = process.env.DEVNET_WALLET_PVT_KEY !== undefined;

const iterations = isDevnet ? 1 : 10;

export const runBenchmark = (name: string, benchmarkFn: () => Promise<void>) => {
bench(
isDevnet ? name : `${name} (x${iterations} times)`,
danielbate marked this conversation as resolved.
Show resolved Hide resolved
async () => {
await benchmarkFn();
},
{ iterations }
);
};
88 changes: 61 additions & 27 deletions internal/benchmarks/src/contract-interaction.bench.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/* eslint-disable import/no-extraneous-dependencies */

import type { WalletUnlocked } from 'fuels';
import { bn } from 'fuels';
import { DEVNET_NETWORK_URL } from '@internal/utils';
import { WalletUnlocked, bn, Provider } from 'fuels';
import { launchTestNode, TestAssetId } from 'fuels/test-utils';
import { bench } from 'vitest';

import type { CounterContract, CallTestContract } from '../test/typegen/contracts';
import { CounterContractFactory, CallTestContractFactory } from '../test/typegen/contracts';
import {
CounterContractFactory,
CallTestContractFactory,
LargeContractFactory,
} from '../test/typegen/contracts';

import { isDevnet, runBenchmark } from './config';

/**
* @group node
* @group browser
Expand All @@ -16,55 +23,82 @@ describe('Contract Interaction Benchmarks', () => {
let callTestContract: CallTestContract;
let wallet: WalletUnlocked;
let cleanup: () => void;
beforeEach(async () => {
const launched = await launchTestNode({
contractsConfigs: [{ factory: CounterContractFactory }, { factory: CallTestContractFactory }],
});

cleanup = launched.cleanup;
contract = launched.contracts[0];
callTestContract = launched.contracts[1];
wallet = launched.wallets[0];
});
const setupTestEnvironment = async () => {
if (isDevnet) {
const provider = await Provider.create(DEVNET_NETWORK_URL);
wallet = new WalletUnlocked(process.env.DEVNET_WALLET_PVT_KEY as string, provider);

const { waitForResult } = await CounterContractFactory.deploy(wallet);
contract = (await waitForResult()).contract;

afterEach(() => {
cleanup();
const { waitForResult: waitForResultCallTestContract } =
await CallTestContractFactory.deploy(wallet);
callTestContract = (await waitForResultCallTestContract()).contract;
} else {
const launched = await launchTestNode({
contractsConfigs: [
{ factory: CounterContractFactory },
{ factory: CallTestContractFactory },
],
});

cleanup = launched.cleanup;
contract = launched.contracts[0];
callTestContract = launched.contracts[1];
wallet = launched.wallets[0];
}
};

beforeAll(setupTestEnvironment);

afterAll(() => {
if (!isDevnet && cleanup) {
cleanup();
}
});

bench('should successfully execute a contract read function', async () => {
runBenchmark('should successfully execute a contract read function', async () => {
const tx = await contract.functions.get_count().call();

const { value } = await tx.waitForResult();

expect(JSON.stringify(value)).toEqual(JSON.stringify(bn(0)));
expect(value).toBeDefined();
});

bench('should successfully execute a contract multi call', async () => {
runBenchmark('should successfully execute a contract multi call', async () => {
const initialValue = 100;
const tx = await contract
.multiCall([contract.functions.increment_counter(100), contract.functions.get_count()])
.multiCall([
contract.functions.increment_counter(initialValue),
contract.functions.get_count(),
])
.call();

const { value } = await tx.waitForResult();

expect(JSON.stringify(value)).toEqual(JSON.stringify([bn(100), bn(100)]));
expect(value).toBeDefined();
});

bench('should successfully write to a contract', async () => {
runBenchmark('should successfully write to a contract', async () => {
const tx = await contract.functions.increment_counter(100).call();
await tx.waitForResult();
});

bench('should successfully execute a contract mint', async () => {
runBenchmark('should successfully execute a contract mint', async () => {
const tx = await callTestContract.functions.mint_coins(TestAssetId.A.value, bn(100)).call();

await tx.waitForResult();
});

bench('should successfully execute a contract deploy', async () => {
runBenchmark('should successfully execute a contract deploy', async () => {
const factory = new CounterContractFactory(wallet);
const { waitForResult } = await factory.deploy();
const { contract: deployedContract } = await waitForResult();
expect(deployedContract).toBeDefined();
});

bench('should successfully execute a contract deploy as blobs', async () => {
danielbate marked this conversation as resolved.
Show resolved Hide resolved
const factory = new LargeContractFactory(wallet);
const { waitForResult } = await factory.deployAsBlobTx({
chunkSizeMultiplier: 0.9,
});
const { contract: deployedContract } = await waitForResult();
expect(deployedContract).toBeDefined();
});
});
Loading