Skip to content

Commit

Permalink
feat!: change b256 addresses to use checksum address (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio authored Oct 12, 2024
1 parent cd36eda commit cdac8d4
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 38 deletions.
9 changes: 9 additions & 0 deletions .changeset/old-lions-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@fuel-connectors/burner-wallet-connector": minor
"@fuel-connectors/evm-connector": minor
"@fuel-connectors/fuel-wallet": minor
"@fuel-connectors/bako-safe": minor
"@fuel-connectors/common": minor
---

feat!: change address return to use toString instead of b256
2 changes: 1 addition & 1 deletion examples/react-app/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from './button';
import Feature from './feature';
import Notification, { type Props as NotificationProps } from './notification';

const DEFAULT_ADDRESS = Address.fromRandom().toB256();
const DEFAULT_ADDRESS = Address.fromRandom().toString();

interface Props {
isSigning: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/bako-safe/tests/BakoSafeConnector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('signMessage()', () => {
const connector = new BakoSafeConnector();

expect(
connector.signMessage(Address.fromRandom().toAddress(), 'message'),
connector.signMessage(Address.fromRandom().toString(), 'message'),
).rejects.toThrowError('Method not implemented.');
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/burner-wallet-connector/src/BurnerWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class BurnerWalletConnector extends FuelConnector {
this.storage.setItem(BURNER_WALLET_STATUS, 'connected'),
]);

const accountAddress = this.burnerWallet?.address.toAddress();
const accountAddress = this.burnerWallet?.address.toString();

this.emit(this.events.connection, true);
this.emit(this.events.currentAccount, accountAddress);
Expand All @@ -178,7 +178,7 @@ export class BurnerWalletConnector extends FuelConnector {
throw Error('Wallet not connected');
}

const account = this.burnerWallet.address.toAddress();
const account = this.burnerWallet.address.toString();

if (!account) {
return [];
Expand Down Expand Up @@ -235,7 +235,7 @@ export class BurnerWalletConnector extends FuelConnector {
throw Error('Wallet not connected');
}

return this.burnerWallet.address.toB256() || null;
return this.burnerWallet.address.toString() || null;
}

async addAssets(_assets: Asset[]): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Burner Wallet Connector', () => {

expect(connector).to.be.an.instanceOf(BurnerWalletConnector);
expect(await connector.currentAccount()).to.be.equal(
wallet.address.toB256(),
wallet.address.toString(),
);
});

Expand All @@ -117,7 +117,7 @@ describe('Burner Wallet Connector', () => {

expect(connector).to.be.an.instanceOf(BurnerWalletConnector);
expect(await connector.currentAccount()).to.be.equal(
wallet.address.toB256(),
wallet.address.toString(),
);
});

Expand All @@ -144,7 +144,7 @@ describe('Burner Wallet Connector', () => {

expect(connector).to.be.an.instanceOf(BurnerWalletConnector);
expect(await connector.currentAccount()).to.be.equal(
wallet2.address.toB256(),
wallet2.address.toString(),
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/PredicateConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export abstract class PredicateConnector extends FuelConnector {
throw Error('No predicate account found');
}

const b256Address = Address.fromDynamicInput(address).toB256();
const b256Address = Address.fromDynamicInput(address).toString();
const { fuelProvider } = await this.getProviders();
const chainId = fuelProvider.getChainId();
const walletAccount = this.predicateAccount.getAccountAddress(
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/PredicateFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class PredicateFactory {
SIGNER: this.adapter.convertAddress(address),
},
);
return Address.fromB256(getPredicateRoot(predicateBytes)).toB256();
return Address.fromB256(getPredicateRoot(predicateBytes)).toString();
});

build = memoize(
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/PredicateWalletAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface PredicateWalletAdapter {

export class EthereumWalletAdapter implements PredicateWalletAdapter {
convertAddress = (address: string): string => {
return Address.fromEvmAddress(address).toB256();
return Address.fromEvmAddress(address).toString();
};

generateFakeAccount = (): FakeAccount => {
Expand Down
2 changes: 1 addition & 1 deletion packages/evm-connector/src/test/evmWalletConnector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function createTransaction(
tx.inputs?.forEach((input) => {
if (
input.type === InputType.Coin &&
hexlify(input.owner) === predicate.address.toB256()
hexlify(input.owner) === predicate.address.toString()
) {
input.predicate = arrayify(predicate.bytes);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-wallet/src/FuelWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class FuelWalletConnector extends FuelConnector {
async currentAccount(): Promise<string | null> {
const account = await this.client.request('currentAccount', {});
if (!account) return null;
return Address.fromDynamicInput(account).toB256();
return Address.fromDynamicInput(account).toString();
}

async signMessage(address: string, message: string): Promise<string> {
Expand Down
50 changes: 25 additions & 25 deletions packages/fuel-wallet/src/tests/FuelWalletConnector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ describe('FuelWalletConnector', () => {
test('should request accounts', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve([
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
]),
);

const connector = new FuelWalletConnector();
const result = await connector.accounts();
expect(result).toEqual([
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
]);
expect(request).toHaveBeenCalledWith('accounts', {});
});

test('should request current account', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
),
);

const connector = new FuelWalletConnector();
const result = await connector.currentAccount();
expect(result).toBe(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(request).toHaveBeenCalledWith('currentAccount', {});
});
Expand All @@ -84,21 +84,21 @@ describe('FuelWalletConnector', () => {
test('should request sign message', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
),
);

const connector = new FuelWalletConnector();
const result = await connector.signMessage(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
'hello',
);
expect(result).toBe(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(request).toHaveBeenCalledWith('signMessage', {
address:
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
message: 'hello',
});
});
Expand All @@ -107,7 +107,7 @@ describe('FuelWalletConnector', () => {
const connector = new FuelWalletConnector();
await expect(
connector.signMessage(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
' ',
),
).rejects.toThrowError('Message is required');
Expand All @@ -116,19 +116,19 @@ describe('FuelWalletConnector', () => {
test('should request send transaction', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
),
);

const connector = new FuelWalletConnector();
const result = await connector.sendTransaction(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
{
type: TransactionType.Create,
},
);
expect(result).toBe(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(request).toHaveBeenCalled();
});
Expand All @@ -137,7 +137,7 @@ describe('FuelWalletConnector', () => {
const connector = new FuelWalletConnector();
await expect(
connector.sendTransaction(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
null as unknown as TransactionRequestLike,
),
).rejects.toThrowError('Transaction is required');
Expand All @@ -148,14 +148,14 @@ describe('FuelWalletConnector', () => {
test('should list assets', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve([
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
]),
);

const connector = new FuelWalletConnector();
const result = await connector.assets();
expect(result).toEqual([
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
]);
expect(request).toHaveBeenCalledWith('assets', {});
});
Expand All @@ -165,20 +165,20 @@ describe('FuelWalletConnector', () => {
test('should get ABI', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
),
);

const connector = new FuelWalletConnector();
const result = await connector.getABI(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(result).toBe(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(request).toHaveBeenCalledWith('getAbi', {
contractId:
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
});
});

Expand All @@ -187,13 +187,13 @@ describe('FuelWalletConnector', () => {

const connector = new FuelWalletConnector();
const result = await connector.addABI(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
{} as FuelABI,
);
expect(result).toBe(true);
expect(request).toHaveBeenCalledWith('addAbi', {
abiMap: {
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb':
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb':
{},
},
});
Expand All @@ -204,12 +204,12 @@ describe('FuelWalletConnector', () => {

const connector = new FuelWalletConnector();
const result = await connector.hasABI(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(result).toBe(true);
expect(request).toHaveBeenCalledWith('getAbi', {
contractId:
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
});
});
});
Expand Down Expand Up @@ -250,14 +250,14 @@ describe('FuelWalletConnector', () => {
test('should return version', async () => {
const request = requestMock.mockReturnValue(
Promise.resolve(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
),
);

const connector = new FuelWalletConnector();
const result = await connector.version();
expect(result).toBe(
'0x1dc6604c6943e7c618ecdee1e815dd4051ebf0a0e822986f5550b960ff4126fb',
'0x1DC6604C6943E7C618ecDeE1e815dD4051EBf0A0E822986F5550B960fF4126fb',
);
expect(request).toHaveBeenCalledWith('version', {
app: '0.0.0',
Expand Down
1 change: 1 addition & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineWorkspace([
{
test: {
include: ['tests/**/*.test.{ts}'],
exclude: ['codeInContextPlugin.test.ts'],
name: 'node',
environment: 'node',
},
Expand Down

0 comments on commit cdac8d4

Please sign in to comment.