Skip to content

Commit

Permalink
refactor: rename NativeAssetId to BaseAssetId (#1121)
Browse files Browse the repository at this point in the history
* refactor: rename `NativeAssetId` to `BaseAssetId`

* fix tests
  • Loading branch information
Dhaiwat10 authored Jul 25, 2023
1 parent 9da0e6a commit 9c8ed7a
Show file tree
Hide file tree
Showing 47 changed files with 242 additions and 230 deletions.
12 changes: 12 additions & 0 deletions .changeset/eighty-taxis-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@fuel-ts/address": minor
"demo-nextjs": patch
"demo-react-cra": patch
"demo-react-vite": patch
"@fuel-ts/docs-snippets": patch
"@fuel-ts/providers": patch
"@fuel-ts/script": patch
"@fuel-ts/wallet": patch
---

`NativeAssetId` has been renamed to `BaseAssetId` for better clarity and consistency with the Rust SDK.
4 changes: 2 additions & 2 deletions apps/demo-nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NativeAssetId, decrypt, encrypt } from "fuels";
import { BaseAssetId, decrypt, encrypt } from "fuels";
import Image from "next/image";

import styles from "./page.module.css";

export default function Home() {
const { log } = console;

log("Hello Fuels", NativeAssetId, encrypt, decrypt);
log("Hello Fuels", BaseAssetId, encrypt, decrypt);

return (
<main className={styles.main}>
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-react-cra/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import { NativeAssetId, encrypt, decrypt } from "fuels";
import { BaseAssetId, encrypt, decrypt } from "fuels";

function App() {
const { log } = console;

log("Hello Fuels", NativeAssetId, encrypt, decrypt);
log("Hello Fuels", BaseAssetId, encrypt, decrypt);

return (
<div className="App">
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-react-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import reactLogo from "./assets/react.svg";
import viteLogo from "/vite.svg";
import "./App.css";

import { NativeAssetId, encrypt, decrypt } from "fuels";
import { BaseAssetId, encrypt, decrypt } from "fuels";

function App() {
const [count, setCount] = useState(0);

const { log } = console;

log("Hello Fuels", NativeAssetId, encrypt, decrypt);
log("Hello Fuels", BaseAssetId, encrypt, decrypt);

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// #region Testing-with-jest-ts
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import fs from 'fs';
import { ContractFactory, Provider, toHex, NativeAssetId } from 'fuels';
import { ContractFactory, Provider, toHex, BaseAssetId } from 'fuels';
import path from 'path';

import { DemoContractAbi__factory } from './generated-types';

describe('ExampleContract', () => {
it('should return the input', async () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');
const wallet = await generateTestWallet(provider, [[1_000, NativeAssetId]]);
const wallet = await generateTestWallet(provider, [[1_000, BaseAssetId]]);

// Deploy
const bytecode = fs.readFileSync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract } from 'fuels';
import { BN, NativeAssetId } from 'fuels';
import { BN, BaseAssetId } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';
Expand All @@ -18,7 +18,7 @@ describe(__filename, () => {
const { value } = await contract.functions
.return_context_amount()
.callParams({
forward: [amountToForward, NativeAssetId],
forward: [amountToForward, BaseAssetId],
})
.call();

Expand All @@ -32,7 +32,7 @@ describe(__filename, () => {
contract.functions
.return_context_amount()
.callParams({
forward: [10, NativeAssetId],
forward: [10, BaseAssetId],
gasLimit: 1,
})
.call()
Expand All @@ -49,7 +49,7 @@ describe(__filename, () => {
const result = await contract.functions
.return_context_amount()
.callParams({
forward: [amountToForward, NativeAssetId],
forward: [amountToForward, BaseAssetId],
gasLimit: contractCallGasLimit,
})
.txParams({
Expand Down
10 changes: 5 additions & 5 deletions apps/docs-snippets/src/guide/contracts/contract-balance.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract } from 'fuels';
import { Wallet, BN, NativeAssetId } from 'fuels';
import { Wallet, BN, BaseAssetId } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';
Expand All @@ -13,21 +13,21 @@ describe(__filename, () => {

it('should successfully get a contract balance', async () => {
// #region contract-balance-3
// #context import { Wallet, BN, NativeAssetId } from 'fuels';
// #context import { Wallet, BN, BaseAssetId } from 'fuels';

const amountToForward = 40;
const amountToTransfer = 10;

const recipient = Wallet.generate();

await contract.functions
.transfer(amountToTransfer, NativeAssetId, recipient.address.toB256())
.transfer(amountToTransfer, BaseAssetId, recipient.address.toB256())
.callParams({
forward: [amountToForward, NativeAssetId],
forward: [amountToForward, BaseAssetId],
})
.call();

const contractBalance = await contract.getBalance(NativeAssetId);
const contractBalance = await contract.getBalance(BaseAssetId);

const expectedBalance = amountToForward - amountToTransfer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract } from 'fuels';
import { NativeAssetId } from 'fuels';
import { BaseAssetId } from 'fuels';

import { SnippetProjectEnum } from '../../../projects';
import { createAndDeployContractFromProject } from '../../utils';
Expand All @@ -16,7 +16,7 @@ describe(__filename, () => {
const cost = await contract.functions
.return_context_amount()
.callParams({
forward: [100, NativeAssetId],
forward: [100, BaseAssetId],
})
.getTransactionCost();

Expand All @@ -31,10 +31,10 @@ describe(__filename, () => {
// #region cost-estimation-2
const scope = contract.multiCall([
contract.functions.return_context_amount().callParams({
forward: [100, NativeAssetId],
forward: [100, BaseAssetId],
}),
contract.functions.return_context_amount().callParams({
forward: [300, NativeAssetId],
forward: [300, BaseAssetId],
}),
]);

Expand Down
4 changes: 2 additions & 2 deletions apps/docs-snippets/src/guide/contracts/multicalls.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract } from 'fuels';
import { NativeAssetId, BN, ContractFactory } from 'fuels';
import { BaseAssetId, BN, ContractFactory } from 'fuels';

import { getSnippetProjectArtifacts, SnippetProjectEnum } from '../../../projects';
import { getTestWallet } from '../../utils';
Expand Down Expand Up @@ -81,7 +81,7 @@ describe(__filename, () => {
.multiCall([
echoContract.functions.echo_u8(10),
contextContract.functions.return_context_amount().callParams({
forward: [100, NativeAssetId],
forward: [100, BaseAssetId],
}),
])
.call();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletUnlocked, Predicate, NativeAssetId, BN, getRandomB256 } from 'fuels';
import { WalletUnlocked, Predicate, BaseAssetId, BN, getRandomB256 } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe(__filename, () => {
await tx2.waitForResult();
// #endregion predicate-with-configurable-constants-2

const destinationBalance = await destinationWallet.getBalance(NativeAssetId);
const destinationBalance = await destinationWallet.getBalance(BaseAssetId);

expect(new BN(destinationBalance).toNumber()).toEqual(amountToTransfer);
});
Expand Down Expand Up @@ -69,7 +69,7 @@ describe(__filename, () => {
await tx2.waitForResult();
// #endregion predicate-with-configurable-constants-3

const destinationBalance = await destinationWallet.getBalance(NativeAssetId);
const destinationBalance = await destinationWallet.getBalance(BaseAssetId);

expect(new BN(destinationBalance).toNumber()).toEqual(amountToTransfer);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CoinQuantityLike, Contract } from 'fuels';
import {
BN,
ContractFactory,
NativeAssetId,
BaseAssetId,
ScriptTransactionRequest,
type WalletUnlocked,
} from 'fuels';
Expand All @@ -29,7 +29,7 @@ describe(__filename, () => {
const seedQuantities: CoinQuantityLike[] = [
[1000, assetIdA],
[500, assetIdB],
[1000, NativeAssetId],
[1000, BaseAssetId],
];

wallet = await getTestWallet(seedQuantities);
Expand Down
10 changes: 5 additions & 5 deletions apps/docs-snippets/src/guide/wallets/transferring-assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Contract, WalletUnlocked } from 'fuels';
import { Address, BN, ContractFactory, NativeAssetId, Wallet } from 'fuels';
import { Address, BN, ContractFactory, BaseAssetId, Wallet } from 'fuels';

import { SnippetProjectEnum, getSnippetProjectArtifacts } from '../../../projects';
import { getTestWallet } from '../../utils';
Expand All @@ -20,12 +20,12 @@ describe(__filename, () => {

it('should successfully transfer asset to another wallet', async () => {
// #region transferring-assets-1
// #context import { Wallet, BN, NativeAssetId } from 'fuels';
// #context import { Wallet, BN, BaseAssetId } from 'fuels';

// #context const senderWallet = Wallet.fromPrivateKey('...');
const destinationWallet = Wallet.generate();
const amountToTransfer = 500;
const assetId = NativeAssetId;
const assetId = BaseAssetId;

const response = await senderWallet.transfer(
destinationWallet.address,
Expand All @@ -46,12 +46,12 @@ describe(__filename, () => {
it('should successfully transfer asset to a deployed contract', async () => {
const contractId = Address.fromAddressOrString(deployedContract.id);
// #region transferring-assets-2
// #context import { Wallet, BN, NativeAssetId } from 'fuels';
// #context import { Wallet, BN, BaseAssetId } from 'fuels';

// #context const senderWallet = Wallet.fromPrivateKey('...');

const amountToTransfer = 400;
const assetId = NativeAssetId;
const assetId = BaseAssetId;
// #context const contractId = Address.fromAddressOrString('0x123...');

const contractBalance = await deployedContract.getBalance(assetId);
Expand Down
4 changes: 2 additions & 2 deletions apps/docs-snippets/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CoinQuantityLike, Contract } from 'fuels';
import {
FUEL_NETWORK_URL,
NativeAssetId,
BaseAssetId,
Provider,
ScriptTransactionRequest,
Wallet,
Expand All @@ -24,7 +24,7 @@ export const getTestWallet = async (seedQuantities?: CoinQuantityLike[]) => {
const quantities: CoinQuantityLike[] = seedQuantities || [
{
amount: 1_000_000,
assetId: NativeAssetId,
assetId: BaseAssetId,
},
];

Expand Down
4 changes: 2 additions & 2 deletions internal/check-imports/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AbiTypeGen } from '@fuel-ts/abi-typegen';
import { runCliAction } from '@fuel-ts/abi-typegen/cli';
import { runTypegen } from '@fuel-ts/abi-typegen/runTypegen';
import { Address } from '@fuel-ts/address';
import { NativeAssetId } from '@fuel-ts/address/configs';
import { BaseAssetId } from '@fuel-ts/address/configs';
import { VM_REGISTER_COUNT } from '@fuel-ts/asm';
import { ContractFactory } from '@fuel-ts/contract';
import { hashTransaction, hashMessage } from '@fuel-ts/hasher';
Expand Down Expand Up @@ -52,7 +52,7 @@ log(runCliAction);
* address
*/
log(Address);
log(NativeAssetId);
log(BaseAssetId);
log(Address.fromPublicKey('asdfasdf'));

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/address/src/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const ZeroBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
export const NativeAssetId = ZeroBytes32;
export const BaseAssetId = ZeroBytes32;
export const EmptyRoot = '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/auth-testing.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import fs from 'fs';
import type { Contract, WalletUnlocked } from 'fuels';
import { AssertFailedRevertError, ContractFactory, NativeAssetId, Provider } from 'fuels';
import { AssertFailedRevertError, ContractFactory, BaseAssetId, Provider } from 'fuels';
import path from 'path';

import FactoryAbi from '../fixtures/forc-projects/auth_testing_contract/out/debug/auth_testing_contract-abi.json';
Expand All @@ -12,7 +12,7 @@ let wallet: WalletUnlocked;
describe('Auth Testing', () => {
beforeAll(async () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');
wallet = await generateTestWallet(provider, [[1_000, NativeAssetId]]);
wallet = await generateTestWallet(provider, [[1_000, BaseAssetId]]);

const bytecode = fs.readFileSync(
path.join(
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/call-test-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from 'fs';
import { BN, bn, toHex, NativeAssetId } from 'fuels';
import { BN, bn, toHex, BaseAssetId } from 'fuels';
import { join } from 'path';

import abiJSON from '../fixtures/forc-projects/call-test-contract/out/debug/call-test-abi.json';
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('CallTestContract', () => {
const { value } = await contract.functions
.return_context_amount()
.callParams({
forward: [1_000_000, NativeAssetId],
forward: [1_000_000, BaseAssetId],
})
.call();
expect(value.toHex()).toBe(bn(1_000_000).toHex());
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/configurable-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import { readFileSync } from 'fs';
import type { CoinQuantityLike, WalletUnlocked } from 'fuels';
import { getRandomB256, BN, ContractFactory, NativeAssetId, Provider } from 'fuels';
import { getRandomB256, BN, ContractFactory, BaseAssetId, Provider } from 'fuels';
import { join } from 'path';

import contractAbi from '../fixtures/forc-projects/configurable-contract/out/debug/configurable-contract-abi.json';
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Configurable Contract', () => {
const quantities: CoinQuantityLike[] = [
{
amount: 1_000_000,
assetId: NativeAssetId,
assetId: BaseAssetId,
},
];

Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-gauge/src/contract-factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import { readFileSync } from 'fs';
import { bn, toHex, Interface, Provider, ContractFactory, NativeAssetId } from 'fuels';
import { bn, toHex, Interface, Provider, ContractFactory, BaseAssetId } from 'fuels';
import { join } from 'path';

import storageSlots from '../fixtures/forc-projects/storage-test-contract/out/debug/storage-test-storage_slots.json';

describe('Contract Factory', () => {
const createContractFactory = async () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');
const wallet = await generateTestWallet(provider, [[5_000_000, NativeAssetId]]);
const wallet = await generateTestWallet(provider, [[5_000_000, BaseAssetId]]);

// load the byteCode of the contract, generated from Sway source
const byteCode = readFileSync(
Expand Down
Loading

0 comments on commit 9c8ed7a

Please sign in to comment.