Skip to content

Commit

Permalink
fix: add typegen for token contract abi + more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jul 6, 2024
1 parent bb47402 commit de20c8c
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 170 deletions.
7 changes: 6 additions & 1 deletion packages/fuel-gauge/src/reentrant-contract-calls.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractFactory, ReceiptType, bn } from 'fuels';
import { ContractFactory, ReceiptType, bn, sleep } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import type { ReentrantBarAbi, ReentrantFooAbi } from '../test/typegen/contracts';
Expand All @@ -16,6 +16,11 @@ import StorageTestContractAbiHex from '../test/typegen/contracts/StorageTestCont
* @group browser
*/
describe('Reentrant Contract Calls', () => {
it.only('dummy test', async () => {
console.log('before');
using node = await launchTestNode();
console.log('after');
});
it('should ensure the SDK returns the proper value for a reentrant call', async () => {
using launched = await launchTestNode({
contractsConfigs: [
Expand Down
62 changes: 27 additions & 35 deletions packages/fuel-gauge/src/storage-test-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
import { toHex, Provider, ContractFactory, FUEL_NETWORK_URL } from 'fuels';
import { generateTestWallet } from 'fuels/test-utils';
import { launchTestNode } from 'fuels/test-utils';

import { FuelGaugeProjectsEnum, getFuelGaugeForcProject } from '../test/fixtures';

const {
binHexlified: bytecode,
abiContents: abi,
storageSlots,
} = getFuelGaugeForcProject(FuelGaugeProjectsEnum.STORAGE_TEST_CONTRACT);

const setup = async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const baseAssetId = provider.getBaseAssetId();
// Create wallet
const wallet = await generateTestWallet(provider, [[1_000_000, baseAssetId]]);
// Deploy contract
// #region contract-deployment-storage-slots
// #context import storageSlots from '../your-sway-project/out/debug/your-sway-project-storage_slots.json';

const factory = new ContractFactory(bytecode, abi, wallet);
const contract = await factory.deployContract({
storageSlots,
});
// #endregion contract-deployment-storage-slots

return contract;
};
import { StorageTestContractAbi__factory } from '../test/typegen';
import StorageTestContractAbiHex from '../test/typegen/contracts/StorageTestContractAbi.hex';

/**
* @group node
* @group browser
*/
describe('StorageTestContract', () => {
let baseAssetId: string;
beforeAll(async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
baseAssetId = provider.getBaseAssetId();
});
it('can increment counter', async () => {
const contract = await setup();
using launched = await launchTestNode({
contractsConfigs: [
{
deployer: StorageTestContractAbi__factory,
bytecode: StorageTestContractAbiHex,
},
],
});

const {
contracts: [contract],
} = launched;

// Call contract
const { value: initializeResult } = await contract.functions.initialize_counter(1300).call();
Expand All @@ -50,9 +34,17 @@ describe('StorageTestContract', () => {
});

it('can increment counter - using custom inline storage slots', async () => {
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = await generateTestWallet(provider, [[500_000, baseAssetId]]);
const factory = new ContractFactory(bytecode, abi, wallet);
using launched = await launchTestNode();

const {
wallets: [wallet],
} = launched;

const factory = new ContractFactory(
StorageTestContractAbiHex,
StorageTestContractAbi__factory.abi,
wallet
);
// #region contract-deployment-storage-slots-inline
const contract = await factory.deployContract({
storageSlots: [
Expand Down
47 changes: 20 additions & 27 deletions packages/fuel-gauge/src/token-test-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { AssetId, BN } from 'fuels';
import { toHex, Provider, Wallet, ContractFactory, bn, FUEL_NETWORK_URL } from 'fuels';
import { expectToThrowFuelError, generateTestWallet } from 'fuels/test-utils';
import { toHex, Wallet, bn } from 'fuels';
import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils';

import { FuelGaugeProjectsEnum, getFuelGaugeForcProject } from '../test/fixtures';

const { binHexlified: bytecode, abiContents: abi } = getFuelGaugeForcProject(
FuelGaugeProjectsEnum.TOKEN_CONTRACT
);

let provider: Provider;
let baseAssetId: string;

const setup = async () => {
// Create wallet
const wallet = await generateTestWallet(provider, [[5_000_000, baseAssetId]]);

// Deploy contract
const factory = new ContractFactory(bytecode, abi, wallet);
const contract = await factory.deployContract();

return contract;
};

beforeAll(async () => {
provider = await Provider.create(FUEL_NETWORK_URL);
baseAssetId = provider.getBaseAssetId();
});
import { TokenAbi__factory } from '../test/typegen';
import TokenAbiHex from '../test/typegen/contracts/TokenAbi.hex';

/**
* @group node
* @group browser
*/

describe('TokenTestContract', () => {
it('Can mint and transfer coins', async () => {
// New wallet to transfer coins and check balance
using launched = await launchTestNode({
contractsConfigs: [
{
deployer: MultiTokenContractAbi__factory,
bytecode: MultiTokenContractAbiHex,
},
],
});

const {
provider,
contracts: [token],
} = launched;

const userWallet = Wallet.generate({ provider });
const token = await setup();
const tokenContractId = { bits: token.id.toB256() };
const addressId = { bits: userWallet.address.toB256() };

Expand Down
Loading

0 comments on commit de20c8c

Please sign in to comment.