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

feat: upgrade to fuel-core 0.10.1 #458

Merged
merged 21 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .changeset/tidy-bulldogs-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@fuel-ts/abi-coder": minor
"@fuel-ts/contract": minor
"@fuel-ts/providers": minor
"@fuel-ts/testcases": minor
"@fuel-ts/transactions": minor
"@fuel-ts/wallet": minor
"@fuel-ts/wallet-manager": minor
---

Upgrade compatibility to fuel-core v0.10.1
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
import type { Interface, JsonAbi } from '@fuel-ts/abi-coder';
import { NativeAssetId } from '@fuel-ts/constants';
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 = 2n ** 64n - 1n;

describe('CallTestContract', () => {
it.each([0n, 1337n, U64_MAX - 1n])('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<bigint>();
expect(value).toEqual(num + 1n);
});
Expand All @@ -62,14 +31,14 @@ describe('CallTestContract', () => {
[{ a: false, b: U64_MAX - 1n }],
[{ a: true, b: U64_MAX - 1n }],
])('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).toEqual(struct.b + 1n);
});

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).toEqual(63n);
Expand All @@ -79,25 +48,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 @@ -172,7 +145,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 @@ -181,17 +154,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 @@ -202,17 +177,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 @@ -225,17 +202,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 @@ -248,7 +227,7 @@ describe('CallTestContract', () => {
});

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

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