Skip to content

Commit

Permalink
refactor: docs snippets utility functions (#1011)
Browse files Browse the repository at this point in the history
* feat: create evm address interface

* feat: create evm address clas

* feat: unit tests for evm address wrapper class

* chore: linting

* chore: linting

* feat: support from public key in evm address

* feat: remove evm address class and unit tests

* feat: create types for B256 Evm and Evm address

* feat: create address utility function to convert a b256 to an evm b256

* feat: add address function to return as evm addres

* feat: add unit tests for address to evm address and utility function

* feat: create snippets util function generate test wallet and deploy a contract

* test: create docs snippets tests for evm address

* chore: remove redundant gitignore from evm address doc snippet contract

* test: rename evm address docs snippet test

* docs: create documentation for evm address

* docs: modify docs snippets for evm address

* docs: add evm address to docs config

* test: alter evm address test asserttions

* docs: update evm address title capitalisation

* feat: add evm address type to typegen

* test: add unit test for evm address type with forc project

* test: add evm address to full typegen test suit

* feat: add ignore evm struct to struct typegen

* feat: add evm address type to supported types in typegen

* chore: changeset

* feat: add forc projects to workspace

* test: add address import to dts test

* refactor: rename helixfied to hexlified

* refactor: use deploy contract test util in types docs snippets test

* chore: changeset

* chore: delete redundant gitignore

* feat: remove address from evm dts

* refactor: clean up remain helix references

* refactor: fix hexlified casing

* chore: force rebuild

* chore: force rebuild

* test: implement deploy project test across more docs tests

* chore: adjusting residual tyops after merging with master

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
danielbate and arboleya committed Jul 24, 2023
1 parent 1b74426 commit 39479c2
Show file tree
Hide file tree
Showing 29 changed files with 79 additions and 196 deletions.
2 changes: 2 additions & 0 deletions .changeset/tame-cats-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
16 changes: 4 additions & 12 deletions apps/docs-snippets/src/guide/contracts/call-parameters.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { BN, NativeAssetId, ContractFactory } from 'fuels';
import { BN, NativeAssetId } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.RETURN_CONTEXT
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
});

it('should successfully execute contract call with forwarded amount', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { Provider, WalletUnlocked, ContractFactory } from 'fuels';
import { Provider, WalletUnlocked } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let deployedContract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.RETURN_CONTEXT
);

const contractFactory = new ContractFactory(binHelixfied, abiContents, wallet);

deployedContract = await contractFactory.deployContract();
deployedContract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
});

it('should successfully update contract instace wallet', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getTestWallet } from '../../utils';
describe(__filename, () => {
let wallet: WalletUnlocked;

const { abiContents: abi, binHelixfied: bin } = getSnippetProjectArtifacts(
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_CONFIGURABLES
);

Expand Down
16 changes: 4 additions & 12 deletions apps/docs-snippets/src/guide/contracts/contract-balance.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { Wallet, BN, ContractFactory, NativeAssetId } from 'fuels';
import { Wallet, BN, NativeAssetId } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.TRANSFER_TO_ADDRESS
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.TRANSFER_TO_ADDRESS);
});

it('should successfully get a contract balance', async () => {
Expand Down
16 changes: 4 additions & 12 deletions apps/docs-snippets/src/guide/contracts/cost-estimation.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { ContractFactory, NativeAssetId } from 'fuels';
import { NativeAssetId } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.RETURN_CONTEXT
);

const contractFactory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await contractFactory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.RETURN_CONTEXT);
});

it('should successfully get transaction cost estimate for a single contract call', async () => {
Expand Down
15 changes: 3 additions & 12 deletions apps/docs-snippets/src/guide/contracts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import type { Contract } from 'fuels';
import { ContractFactory } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
});

it('should successfully call contract and echo values', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe(__filename, () => {
const depositorArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.TOKEN_DEPOSITOR);

simpleToken = await new ContractFactory(
tokenArtifacts.binHelixfied,
tokenArtifacts.binHexlified,
tokenArtifacts.abiContents,
wallet
).deployContract();

tokenDepositor = await new ContractFactory(
depositorArtifacts.binHelixfied,
depositorArtifacts.binHexlified,
depositorArtifacts.abiContents,
wallet
).deployContract();
Expand Down
14 changes: 4 additions & 10 deletions apps/docs-snippets/src/guide/contracts/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import type { Contract } from 'fuels';
import { BN, ContractFactory } from 'fuels';
import { BN } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(SnippetProjectEnum.LOG_VALUES);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.LOG_VALUES);
});

it('should successfully execute contract call with forwarded amount', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe(__filename, () => {
let contract: Contract;
let contractId: AbstractAddress;
let wallet: WalletUnlocked;
const { abiContents: abi, binHelixfied: bin } = getSnippetProjectArtifacts(
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
);

Expand Down
6 changes: 3 additions & 3 deletions apps/docs-snippets/src/guide/contracts/multicalls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ describe(__filename, () => {
const contextArtifacts = getSnippetProjectArtifacts(SnippetProjectEnum.RETURN_CONTEXT);

const factory1 = new ContractFactory(
echoArtifacts.binHelixfied,
echoArtifacts.binHexlified,
echoArtifacts.abiContents,
wallet
);
const factory2 = new ContractFactory(
counterArtifacts.binHelixfied,
counterArtifacts.binHexlified,
counterArtifacts.abiContents,
wallet
);
const factory3 = new ContractFactory(
contextArtifacts.binHelixfied,
contextArtifacts.binHexlified,
contextArtifacts.abiContents,
wallet
);
Expand Down
15 changes: 3 additions & 12 deletions apps/docs-snippets/src/guide/contracts/read-only-calls.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import type { Contract } from 'fuels';
import { ContractFactory } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
});

it('should successfully execute a read only call', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import type { Contract } from 'fuels';
import { BN, ContractFactory } from 'fuels';
import { BN } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(SnippetProjectEnum.COUNTER);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.COUNTER);
});

it('should successfully execute contract call with txParams', async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-snippets/src/guide/predicates/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FUEL_NETWORK_URL, Provider, Predicate } from 'fuels';
import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';

describe(__filename, () => {
const { abiContents: jsonAbi, binHelixfied: binary } = getSnippetProjectArtifacts(
const { abiContents: jsonAbi, binHexlified: binary } = getSnippetProjectArtifacts(
SnippetProjectEnum.RETURN_TRUE_PREDICATE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getTestWallet } from '../../utils';
describe(__filename, () => {
let wallet: WalletUnlocked;

const { abiContents: abi, binHelixfied: bin } = getSnippetProjectArtifacts(
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.WHITELISTED_ADDRESS_PREDICATE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getTestWallet } from '../../utils';
describe(__filename, () => {
let walletWithFunds: WalletUnlocked;

const { abiContents: abi, binHelixfied: bin } = getSnippetProjectArtifacts(
const { abiContents: abi, binHexlified: bin } = getSnippetProjectArtifacts(
SnippetProjectEnum.SIMPLE_PREDICATE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe(__filename, () => {
const assetIdB = '0x0101010101010101010101010101010101010101010101010101010101010101';
const assetIdA = '0x0202020202020202020202020202020202020202020202020202020202020202';

const { binHelixfied: scriptBin, abiContents } = getSnippetProjectArtifacts(
const { binHexlified: scriptBin, abiContents } = getSnippetProjectArtifacts(
SnippetProjectEnum.SCRIPT_TRANSFER_TO_CONTRACT
);

const { abiContents: contractAbi, binHelixfied: contractBin } = getSnippetProjectArtifacts(
const { abiContents: contractAbi, binHexlified: contractBin } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { getTestWallet } from '../../utils';
describe(__filename, () => {
let wallet: WalletUnlocked;

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(SnippetProjectEnum.SUM_SCRIPT);
const { abiContents, binHexlified } = getSnippetProjectArtifacts(SnippetProjectEnum.SUM_SCRIPT);

beforeAll(async () => {
wallet = await getTestWallet();
});

it('should successfully sum setted configurable constant with inpputed value', async () => {
// #region script-with-configurable-contants-2
const script = new Script(binHelixfied, abiContents, wallet);
const script = new Script(binHexlified, abiContents, wallet);

const configurableConstants = {
AMOUNT: 81,
Expand Down
16 changes: 4 additions & 12 deletions apps/docs-snippets/src/guide/types/arrays.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { BN, ContractFactory } from 'fuels';
import { BN } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_U64_ARRAY
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_U64_ARRAY);
});

it('should successfully demonstrate typed arrays examples', () => {
Expand Down
16 changes: 4 additions & 12 deletions apps/docs-snippets/src/guide/types/bits512.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type { Contract } from 'fuels';
import { ContractFactory, Wallet } from 'fuels';
import { Wallet } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';

describe(__filename, () => {
let contract: Contract;

beforeAll(async () => {
const wallet = await getTestWallet();

const { abiContents, binHelixfied } = getSnippetProjectArtifacts(
SnippetProjectEnum.ECHO_VALUES
);

const factory = new ContractFactory(binHelixfied, abiContents, wallet);

contract = await factory.deployContract();
contract = await createAndDeployContractFromProject(SnippetProjectEnum.ECHO_VALUES);
});

it('should successfully call contract function and validate b512', async () => {
Expand Down
Loading

0 comments on commit 39479c2

Please sign in to comment.