Skip to content

Commit

Permalink
chore: use pyth large contract + update test config
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Sep 13, 2024
1 parent 2e38db3 commit 2592c90
Show file tree
Hide file tree
Showing 24 changed files with 3,108 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .changeset/ninety-carpets-watch.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@internal/benchmarks": minor
"@internal/benchmarks": patch
---

chore: run benchmarking utility in devnet environment
File renamed without changes.
47 changes: 24 additions & 23 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
name: Benchmarks
on:
pull_request:
branches:
- master
push:
branches-ignore:
- master
# Uncomment this when we want to run benchmarks on PRs
# name: Benchmarks
# on:
# pull_request:
# branches:
# - master
# push:
# branches-ignore:
# - master

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

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

- name: Pretest
run: pnpm pretest
# - name: Pretest
# run: pnpm pretest

- name: Run Node benchmarks
uses: CodSpeedHQ/action@v3
with:
run: pnpm bench:node
token: ${{ secrets.CODSPEED_TOKEN }}
# - name: Run Node benchmarks
# uses: CodSpeedHQ/action@v3
# with:
# run: pnpm bench:node
# token: ${{ secrets.CODSPEED_TOKEN }}
66 changes: 46 additions & 20 deletions internal/benchmarks/src/contract-interaction.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ 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,
PythContractFactory,
} from '../test/typegen/contracts';

import { DEVNET_CONFIG } from './config';
/**
Expand Down Expand Up @@ -44,38 +48,60 @@ describe('Contract Interaction Benchmarks', () => {
});
}

bench('should successfully execute a contract read function', async () => {
const tx = await contract.functions.get_count().call();
bench('should successfully execute a contract read function 10 times', async () => {
for (let i = 0; i < 10; i++) {
const tx = await contract.functions.get_count().call();

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

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

bench('should successfully execute a contract multi call', async () => {
const tx = await contract
.multiCall([contract.functions.increment_counter(100), contract.functions.get_count()])
.call();
bench('should successfully execute a contract multi call 10 times', async () => {
const initialValue = 100;
for (let i = 1; i < 11; i++) {
const tx = await contract
.multiCall([contract.functions.increment_counter(100), contract.functions.get_count()])
.call();

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

expect(JSON.stringify(value)).toEqual(JSON.stringify([bn(100), bn(100)]));
expect(JSON.stringify(value)).toEqual(
JSON.stringify([bn(initialValue * i), bn(initialValue * i)])
);
}
});

bench('should successfully write to a contract', async () => {
const tx = await contract.functions.increment_counter(100).call();
await tx.waitForResult();
bench('should successfully write to a contract 10 times', async () => {
for (let i = 0; i < 10; i++) {
const tx = await contract.functions.increment_counter(100).call();
await tx.waitForResult();
}
});

bench('should successfully execute a contract mint', async () => {
const tx = await callTestContract.functions.mint_coins(TestAssetId.A.value, bn(100)).call();
bench('should successfully execute a contract mint 10 times', async () => {
for (let i = 0; i < 10; i++) {
const tx = await callTestContract.functions.mint_coins(TestAssetId.A.value, bn(100)).call();
await tx.waitForResult();
}
});

bench('should successfully execute a contract deploy 10 times', async () => {
for (let i = 0; i < 10; i++) {
const factory = new CounterContractFactory(wallet);
const { waitForResult } = await factory.deploy();
const { contract: deployedContract } = await waitForResult();

await tx.waitForResult();
expect(deployedContract).toBeDefined();
}
});

bench('should successfully execute a contract deploy', async () => {
const factory = new CounterContractFactory(wallet);
const { waitForResult } = await factory.deploy();
bench('should successfully execute a contract deploy as blobs', async () => {
const factory = new PythContractFactory(wallet);
const { waitForResult } = await factory.deployAsBlobTx({
chunkSizeMultiplier: 0.9,
});
const { contract: deployedContract } = await waitForResult();

expect(deployedContract).toBeDefined();
Expand Down
11 changes: 10 additions & 1 deletion internal/benchmarks/src/cost-estimation.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */

import type { TransferParams, WalletUnlocked } from 'fuels';
import type { TransferParams, WalletUnlocked, BytesLike } from 'fuels';
import { Wallet, Provider, ScriptTransactionRequest } from 'fuels';
import { launchTestNode, TestAssetId } from 'fuels/test-utils';
import { bench } from 'vitest';
Expand Down Expand Up @@ -51,8 +51,17 @@ describe('Cost Estimation Benchmarks', () => {
beforeAll(async () => {
const { networkUrl } = DEVNET_CONFIG;
provider = await Provider.create(networkUrl);
const wallet = Wallet.fromPrivateKey(
process.env.DEVNET_WALLET_PVT_KEY as BytesLike,
provider
);

setup(provider);

const contractFactory = new CallTestContractFactory(wallet);
const { waitForResult } = await contractFactory.deploy<CallTestContract>();
const { contract: deployedContract } = await waitForResult();
contract = deployedContract;
});
} else {
beforeEach(async () => {
Expand Down
56 changes: 30 additions & 26 deletions internal/benchmarks/src/transaction-results.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,41 @@ describe('Transaction Submission Benchmarks', () => {
}
});

bench('should successfully perform a batch transfer', async () => {
const amountToTransfer1 = 989;
const amountToTransfer2 = 699;
const amountToTransfer3 = 122;

const transferParams: TransferParams[] = [
{
destination: receiver1.address,
amount: amountToTransfer1,
assetId: provider.getBaseAssetId(),
},
{ destination: receiver2.address, amount: amountToTransfer2, assetId: TestAssetId.A.value },
{ destination: receiver3.address, amount: amountToTransfer3, assetId: TestAssetId.B.value },
];

const tx = await wallet.batchTransfer(transferParams);
bench('should successfully perform a batch transfer 10 times', async () => {
for (let i = 0; i < 10; i++) {
const amountToTransfer1 = 989;
const amountToTransfer2 = 699;
const amountToTransfer3 = 122;

const { isStatusSuccess } = await tx.waitForResult();
const transferParams: TransferParams[] = [
{
destination: receiver1.address,
amount: amountToTransfer1,
assetId: provider.getBaseAssetId(),
},
{ destination: receiver2.address, amount: amountToTransfer2, assetId: TestAssetId.A.value },
{ destination: receiver3.address, amount: amountToTransfer3, assetId: TestAssetId.B.value },
];

expect(isStatusSuccess).toBeTruthy();
const tx = await wallet.batchTransfer(transferParams);

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

expect(isStatusSuccess).toBeTruthy();
}
});

bench('should successfully withdraw to the base layer', async () => {
const txParams = {
witnessLimit: 800,
maxFee: 100_000,
};
bench('should successfully withdraw to the base layer 10 times', async () => {
for (let i = 0; i < 10; i++) {
const txParams = {
witnessLimit: 800,
maxFee: 100_000,
};

const pendingTx = await wallet.withdrawToBaseLayer(receiver1.address, 500, txParams);
const { transaction } = await pendingTx.waitForResult();
const pendingTx = await wallet.withdrawToBaseLayer(receiver1.address, 500, txParams);
const { transaction } = await pendingTx.waitForResult();

expect(transaction).toBeDefined();
expect(transaction).toBeDefined();
}
});
});
7 changes: 6 additions & 1 deletion internal/benchmarks/test/fixtures/forc-projects/Forc.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[workspace]
members = ["call-test-contract", "counter-contract"]
members = [
"call-test-contract",
"counter-contract",
"pyth-contract",
"pyth-interface",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "pyth-contract"

[dependencies]
pyth_interface = { path = "../pyth-interface" }
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.4.4" }
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.21.0" }
Loading

0 comments on commit 2592c90

Please sign in to comment.