Skip to content

Commit

Permalink
merge: master
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizAsFight committed Sep 2, 2022
2 parents 7706d18 + 47a28f5 commit 3bcd5fd
Show file tree
Hide file tree
Showing 96 changed files with 1,007 additions and 387 deletions.
6 changes: 0 additions & 6 deletions .changeset/cold-sheep-reflect.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/curvy-bears-tell.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/eight-baboons-repeat.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/tidy-parrots-care.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/weak-dancers-tell.md

This file was deleted.

15 changes: 15 additions & 0 deletions packages/abi-coder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## 0.13.0

### Minor Changes

- [#466](https://github.com/FuelLabs/fuels-ts/pull/466) [`745e65b`](https://github.com/FuelLabs/fuels-ts/commit/745e65bc563ab8cace6f73e2715a6eaaae93fda5) Thanks [@luizstacio](https://github.com/luizstacio)! - Add support to flat abi on interface

* [#458](https://github.com/FuelLabs/fuels-ts/pull/458) [`9190cee`](https://github.com/FuelLabs/fuels-ts/commit/9190cee45529b6c3fcffb2a12b1ef6319b2b39df) Thanks [@LuizAsFight](https://github.com/LuizAsFight)! - Upgrade compatibility to fuel-core v0.10.1

### Patch Changes

- [#471](https://github.com/FuelLabs/fuels-ts/pull/471) [`dfb2612`](https://github.com/FuelLabs/fuels-ts/commit/dfb261222c17cf6f158f475d91b3414996300066) Thanks [@camsjams](https://github.com/camsjams)! - add option type improvement

- Updated dependencies []:
- @fuel-ts/math@0.13.0

## 0.12.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/abi-coder",
"version": "0.12.0",
"version": "0.13.0",
"description": "",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"typedocMain": "src/index.ts",
Expand Down
9 changes: 9 additions & 0 deletions packages/address/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 0.13.0

### Patch Changes

- Updated dependencies []:
- @fuel-ts/constants@0.13.0
- @fuel-ts/interfaces@0.13.0
- @fuel-ts/keystore@0.13.0

## 0.12.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/address/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/address",
"version": "0.12.0",
"version": "0.13.0",
"description": "Utilities for encoding and decoding addresses",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"typedocMain": "./src/index.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/constants/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log

## 0.13.0

## 0.12.0

## 0.11.0
Expand Down
2 changes: 1 addition & 1 deletion packages/constants/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/constants",
"version": "0.12.0",
"version": "0.13.0",
"description": "",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"typedocMain": "src/index.ts",
Expand Down
28 changes: 28 additions & 0 deletions packages/contract/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Change Log

## 0.13.0

### Minor Changes

- [#466](https://github.com/FuelLabs/fuels-ts/pull/466) [`745e65b`](https://github.com/FuelLabs/fuels-ts/commit/745e65bc563ab8cace6f73e2715a6eaaae93fda5) Thanks [@luizstacio](https://github.com/luizstacio)! - Add support to flat abi on interface

* [#456](https://github.com/FuelLabs/fuels-ts/pull/456) [`48285d4`](https://github.com/FuelLabs/fuels-ts/commit/48285d48b6929e3104c480dddb18d2878be6c478) Thanks [@QuinnLee](https://github.com/QuinnLee)! - Failures now output the reason

- [#458](https://github.com/FuelLabs/fuels-ts/pull/458) [`9190cee`](https://github.com/FuelLabs/fuels-ts/commit/9190cee45529b6c3fcffb2a12b1ef6319b2b39df) Thanks [@LuizAsFight](https://github.com/LuizAsFight)! - Upgrade compatibility to fuel-core v0.10.1

### Patch Changes

- [#471](https://github.com/FuelLabs/fuels-ts/pull/471) [`dfb2612`](https://github.com/FuelLabs/fuels-ts/commit/dfb261222c17cf6f158f475d91b3414996300066) Thanks [@camsjams](https://github.com/camsjams)! - add option type improvement

- Updated dependencies [[`745e65b`](https://github.com/FuelLabs/fuels-ts/commit/745e65bc563ab8cace6f73e2715a6eaaae93fda5), [`48285d4`](https://github.com/FuelLabs/fuels-ts/commit/48285d48b6929e3104c480dddb18d2878be6c478), [`9190cee`](https://github.com/FuelLabs/fuels-ts/commit/9190cee45529b6c3fcffb2a12b1ef6319b2b39df), [`5d4d6ce`](https://github.com/FuelLabs/fuels-ts/commit/5d4d6ce7fa1a23deae3f41be94c9fe2ee9851772), [`dfb2612`](https://github.com/FuelLabs/fuels-ts/commit/dfb261222c17cf6f158f475d91b3414996300066)]:
- @fuel-ts/abi-coder@0.13.0
- @fuel-ts/script@0.13.0
- @fuel-ts/providers@0.13.0
- @fuel-ts/transactions@0.13.0
- @fuel-ts/wallet@0.13.0
- @fuel-ts/address@0.13.0
- @fuel-ts/constants@0.13.0
- @fuel-ts/interfaces@0.13.0
- @fuel-ts/keystore@0.13.0
- @fuel-ts/math@0.13.0
- @fuel-ts/merkle@0.13.0
- @fuel-ts/sparsemerkle@0.13.0

## 0.12.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fuel-ts/contract",
"version": "0.12.0",
"version": "0.13.0",
"description": "",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"typedocMain": "src/index.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,25 @@
import type { Interface, JsonAbi } from '@fuel-ts/abi-coder';
import { NativeAssetId } from '@fuel-ts/constants';
import { BN, bn, toHex } from '@fuel-ts/math';
import { Provider } from '@fuel-ts/providers';
import type { Wallet } from '@fuel-ts/wallet';
import { TestUtils } from '@fuel-ts/wallet';
import { readFileSync } from 'fs';
import { join } from 'path';

import type Contract from '../../contracts/contract';
import ContractFactory from '../../contracts/contract-factory';
import { createSetupConfig } from '../test-utils';

import abiJSON from './out/debug/call-test-flat-abi.json';

const contractBytecode = readFileSync(join(__dirname, './out/debug/call-test.bin'));

let contractInstance: Contract;
const deployContract = async (factory: ContractFactory, useCache: boolean = true) => {
if (contractInstance && useCache) return contractInstance;
if (!useCache) {
return factory.deployContract({
gasPrice: 1,
bytePrice: 1,
});
}
contractInstance = await factory.deployContract();
return contractInstance;
};

let walletInstance: Wallet;
const createWallet = async () => {
if (walletInstance) return walletInstance;
const provider = new Provider('http://127.0.0.1:4000/graphql');
walletInstance = await TestUtils.generateTestWallet(provider, [
[5_000_000, NativeAssetId],
[5_000_000, '0x0101010101010101010101010101010101010101010101010101010101010101'],
]);
return walletInstance;
};

export const setup = async (abi: JsonAbi | Interface = abiJSON, useCache: boolean = true) => {
// Create wallet
const wallet = await createWallet();
const factory = new ContractFactory(contractBytecode, abi, wallet);
const contract = await deployContract(factory, useCache);
return contract;
};
const setupContract = createSetupConfig({
contractBytecode,
abi: abiJSON,
cache: true,
});

const U64_MAX = bn(2).pow(64).sub(1);

describe('CallTestContract', () => {
it.each([0, 1337, U64_MAX.sub(1)])('can call a contract with u64 (%p)', async (num) => {
const contract = await setup();
const contract = await setupContract();
const { value } = await contract.functions.foo(num).call<BN>();
expect(value.toHex()).toEqual(bn(num).add(1).toHex());
});
Expand All @@ -63,14 +32,14 @@ describe('CallTestContract', () => {
[{ a: false, b: U64_MAX.sub(1) }],
[{ a: true, b: U64_MAX.sub(1) }],
])('can call a contract with structs (%p)', async (struct) => {
const contract = await setup();
const contract = await setupContract();
const { value } = await contract.functions.boo(struct).call();
expect(value.a).toEqual(!struct.a);
expect(value.b.toHex()).toEqual(bn(struct.b).add(1).toHex());
});

it('can call a function with empty arguments', async () => {
const contract = await setup();
const contract = await setupContract();

const { value: value0 } = await contract.functions.barfoo(0).call();
expect(value0.toHex()).toEqual(toHex(63));
Expand All @@ -80,25 +49,29 @@ describe('CallTestContract', () => {
});

it('function with empty return output configured should resolve undefined', async () => {
const contract = await setup([
{
type: 'function',
name: 'return_void',
outputs: [{ type: '()', name: 'foo' }],
},
]);
const contract = await setupContract({
abi: [
{
type: 'function',
name: 'return_void',
outputs: [{ type: '()', name: 'foo' }],
},
],
});

const { value } = await contract.functions.return_void().call();
expect(value).toEqual(undefined);
});

it('function with empty return should resolve undefined', async () => {
const contract = await setup([
{
type: 'function',
name: 'return_void',
},
]);
const contract = await setupContract({
abi: [
{
type: 'function',
name: 'return_void',
},
],
});

// Call method with no params but with no result and no value on config
const { value } = await await contract.functions.return_void().call();
Expand Down Expand Up @@ -173,7 +146,7 @@ describe('CallTestContract', () => {
])(
`Test call with multiple arguments and different types -> %s`,
async (method, { values, expected }) => {
const contract = await setup();
const contract = await setupContract();

const { value } = await contract.functions[method](...values).call();

Expand All @@ -186,17 +159,19 @@ describe('CallTestContract', () => {
);

it('Forward amount value on contract call', async () => {
const contract = await setup([
{
type: 'function',
name: 'return_context_amount',
outputs: [
{
type: 'u64',
},
],
},
]);
const contract = await setupContract({
abi: [
{
type: 'function',
name: 'return_context_amount',
outputs: [
{
type: 'u64',
},
],
},
],
});
const { value } = await contract.functions
.return_context_amount()
.callParams({
Expand All @@ -207,17 +182,19 @@ describe('CallTestContract', () => {
});

it('Forward asset_id on contract call', async () => {
const contract = await setup([
{
type: 'function',
name: 'return_context_asset',
outputs: [
{
type: 'b256',
},
],
},
]);
const contract = await setupContract({
abi: [
{
type: 'function',
name: 'return_context_amount',
outputs: [
{
type: 'u64',
},
],
},
],
});

const assetId = '0x0101010101010101010101010101010101010101010101010101010101010101';
const { value } = await contract.functions
Expand All @@ -230,17 +207,19 @@ describe('CallTestContract', () => {
});

it('Forward asset_id on contract simulate call', async () => {
const contract = await setup([
{
type: 'function',
name: 'return_context_asset',
outputs: [
{
type: 'b256',
},
],
},
]);
const contract = await setupContract({
abi: [
{
type: 'function',
name: 'return_context_asset',
outputs: [
{
type: 'b256',
},
],
},
],
});

const assetId = '0x0101010101010101010101010101010101010101010101010101010101010101';
const { value } = await contract.functions
Expand All @@ -253,7 +232,7 @@ describe('CallTestContract', () => {
});

it('can make multiple calls', async () => {
const contract = await setup();
const contract = await setupContract();

const num = 1337;
const numC = 10;
Expand Down
Loading

0 comments on commit 3bcd5fd

Please sign in to comment.