Skip to content

Commit

Permalink
feat: address checksum check on send tx (#1578)
Browse files Browse the repository at this point in the history
- Upgrade Fuel SDK to 0.95.0
- Create and store Provider in network machine
- Add address validation to send screen. Only user addresses allowed
- Execute checksum on destination address
- Now addresses are stored in indexdb using a standard, b256 pattern.
Fixes mismatches between addresses types


https://github.com/user-attachments/assets/8e9e5f35-2287-45f2-9a84-146d8b91fa42

---------

Co-authored-by: luizstacio <[email protected]>
Co-authored-by: LuizAsFight <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2024
1 parent a94e985 commit 8851681
Show file tree
Hide file tree
Showing 66 changed files with 3,499 additions and 5,265 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-fans-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Add address type validation to send screen
2 changes: 1 addition & 1 deletion .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
rust-version:
default: 1.77.2
forc-components:
default: 'forc@0.63.1, fuel-core@0.33.0'
default: 'forc@0.65.2, fuel-core@0.38.0'

runs:
using: 'composite'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ jobs:
tests-e2e-contracts:
name: E2E Contract Tests - Local
runs-on: buildjet-4vcpu-ubuntu-2204
# Commented until the Playwright bug is fixed
if: false
steps:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
Expand Down
4 changes: 0 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Load nvm (if you're using it)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# Run lint-staged
pnpm lint-staged
4 changes: 2 additions & 2 deletions Forc.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[package]]
name = "core"
source = "path+from-root-4BB20845430AF9CF"
source = "path+from-root-8357A6DDC5F39D14"

[[package]]
name = "custom_asset"
Expand All @@ -23,7 +23,7 @@ dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.63.5#31a1d6f98395f571cd3674b492d9bf4773c55f65"
source = "git+https://github.com/fuellabs/sway?tag=v0.65.2#66bb430395daf5b8f7205f7b9d8d008e2e812d54"
dependencies = ["core"]

[[package]]
Expand Down
8 changes: 4 additions & 4 deletions docker/fuel-core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# We should be supporting always the same fuel-core version as the fuels (ts-sdk)
# https://github.com/FuelLabs/fuels-ts/blob/master/internal/fuel-core/VERSION
FROM ghcr.io/fuellabs/fuel-core:v0.35.0
FROM ghcr.io/fuellabs/fuel-core:v0.38.0

# dependencies
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -21,15 +21,15 @@ RUN git clone \
https://github.com/FuelLabs/chain-configuration.git \
/chain-configuration && \
cd /chain-configuration && \
git checkout 6cea45da59bb105a02fb0b115c7ef03f3a690ba1
git checkout f31f565905e001b4d6ed9c9d09479dc961ad7367

# Copy the base local configuration
RUN cp -R /chain-configuration/local/* ./

# Copy the testnet consensus parameters and state transition bytecode
RUN cp /chain-configuration/upgradelog/ignition-devnet/consensus_parameters/6.json \
RUN cp /chain-configuration/upgradelog/ignition-devnet/consensus_parameters/13.json \
./latest_consensus_parameters.json
RUN cp /chain-configuration/upgradelog/ignition-devnet/state_transition_function/9.wasm \
RUN cp /chain-configuration/upgradelog/ignition-devnet/state_transition_function/14.wasm \
./state_transition_bytecode.wasm

# update local state_config with custom genesis coins config
Expand Down
6 changes: 3 additions & 3 deletions examples/cra-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"start": "vite"
},
"dependencies": {
"@fuels/connectors": "0.28.0",
"@fuels/react": "0.28.0",
"@fuels/connectors": "0.35.0",
"@fuels/react": "0.35.0",
"@tanstack/react-query": "5.28.4",
"fuels": "pr-3167",
"fuels": "0.96.0",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
5 changes: 5 additions & 0 deletions examples/cra-dapp/src/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 14px;
margin: 0;
padding: 0;
max-width: 100vw;
max-height: 100vh;
overflow-x: hidden;
}

.App {
Expand Down
14 changes: 13 additions & 1 deletion examples/cra-dapp/src/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function Connected() {
const { networks } = useNetworks();
const { selectNetworkAsync, isPending: isSelectingNetwork } =
useSelectNetwork();

const { addNetworkAsync, isPending: isAddingNetwork } = useAddNetwork();

return (
Expand Down Expand Up @@ -165,6 +164,19 @@ export function Connected() {
>
{isAddingNetwork ? 'Loading...' : 'Add testnet'}
</button>
<button
type="button"
onClick={async () => {
try {
const account = await fuel.currentAccount();
console.log(await fuel.signMessage(account!, 'test message'));
} catch (e) {
console.error(e);
}
}}
>
{isAddingNetwork ? 'Signing...' : 'Sign message'}
</button>
</div>

<div className="Accounts">
Expand Down
4 changes: 2 additions & 2 deletions fuel-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
channel = "testnet"

[components]
fuel-core = "0.35.0"
forc = "0.63.5"
fuel-core = "0.38.0"
forc = "0.65.2"
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"@changesets/cli": "^2.26.2",
"@fuels/ts-config": "0.20.0",
"@jest/types": "29.6.3",
"@playwright/test": "^1.46.1",
"@types/jest": "^29.5.5",
"@types/node": "20.8.4",
"@types/react": "^18.3.3",
Expand All @@ -89,7 +88,8 @@
"ts-node": "^10.9.1",
"turbo": "^1.10.15",
"typescript": "^5.2.2",
"updates": "^15.0.2"
"updates": "^15.0.2",
"@playwright/test": "1.46.1"
},
"pnpm": {
"peerDependencyRules": {
Expand Down Expand Up @@ -122,7 +122,8 @@
"micromatch@<4.0.8": ">=4.0.8",
"send@<0.19.0": ">=0.19.0",
"serve-static@<1.16.0": ">=1.16.0",
"rollup@>=4.0.0 <4.22.4": ">=4.22.4"
"rollup@>=4.0.0 <4.22.4": ">=4.22.4",
"fuels": "0.96.0"
}
}
}
3 changes: 2 additions & 1 deletion packages/app/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const config: JestConfigWithTsJest = {
useESM: true,
diagnostics: {
ignoreCodes: [1343],
warnOnly: true,
pretty: true,
},
astTransformers: {
before: [
Expand Down Expand Up @@ -65,7 +67,6 @@ const config: JestConfigWithTsJest = {
'^react-dom$': require.resolve('react-dom'),
'^uuid$': require.resolve('uuid'),
'^@web3modal/core$': require.resolve('@web3modal/core'),
'^@fuels/connectors$': require.resolve('@fuels/connectors'),
},
};

Expand Down
26 changes: 26 additions & 0 deletions packages/app/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jest.mock('react-dom/test-utils', () => {
};
});

console.warn = jest.fn();

const noop = () => {};
Object.defineProperty(window, 'scrollTo', { value: noop, writable: true });
Object.defineProperty(window, 'localStorage', { value: localStorageMock });
Expand All @@ -50,3 +52,27 @@ if (process.env.CI) {
logErrorsBeforeRetry: true,
});
}

const _mockNetworks = [
{
asset_id: 'TKN',
name: 'Token',
type: 'token',
symbol: 'TKN',
decimals: 9,
},
{
asset_id: 'ETH',
name: 'Ethereum',
type: 'token',
symbol: 'ETH',
decimals: 18,
},
{
asset_id: 'Fuel',
name: 'Fuel',
type: 'token',
symbol: 'Fuel',
decimals: 9,
},
];
7 changes: 3 additions & 4 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
"@fuel-ui/test-utils": "0.17.0",
"@fuel-wallet/connections": "workspace:*",
"@fuels/local-storage": "0.20.0",
"@fuels/react": "0.21.0",
"@fuels/react-xstore": "0.20.0",
"@hookform/resolvers": "3.3.2",
"@hookform/resolvers": "3.9.0",
"@react-aria/utils": "3.21.0",
"@sentry/react": "8.33.1",
"@storybook/addon-viewport": "7.4.6",
Expand All @@ -43,7 +42,7 @@
"events": "3.3.0",
"fake-indexeddb": "4.0.2",
"framer-motion": "10.16.4",
"fuels": "pr-3167",
"fuels": "0.96.0",
"json-edit-react": "1.13.3",
"json-rpc-2.0": "1.7.0",
"lodash.debounce": "4.0.8",
Expand All @@ -63,7 +62,7 @@
"devDependencies": {
"@crxjs/vite-plugin": "1.0.14",
"@fuel-wallet/types": "workspace:*",
"@fuels/connectors": "0.5.0",
"@fuels/connectors": "0.35.0",
"@playwright/test": "1.46.1",
"@sentry/cli": "2.33.1",
"@storybook/addon-a11y": "7.4.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const playwrightConfig: PlaywrightTestConfig = {
],
webServer: {
command: 'NODE_ENV=test pnpm dev:crx',
port: Number(PORT),
reuseExistingServer: true,
port: Number(PORT),
timeout: 20000,
},
use: {
Expand Down
18 changes: 13 additions & 5 deletions packages/app/playwright/crx/crx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../mocks';

import {
Address,
type Asset,
type NetworkFuel,
Provider,
Expand Down Expand Up @@ -316,12 +317,19 @@ test.describe('FuelWallet Extension', () => {
});

await test.step('window.fuel.getWallet()', async () => {
const isCorrectAddress = blankPage.evaluate(async () => {
const currentAccount = await window.fuel.currentAccount();
const wallet = await window.fuel.getWallet(currentAccount);
return wallet.address.toString() === currentAccount;
const currentAccount = await blankPage.evaluate(async () => {
return window.fuel.currentAccount();
});
expect(await isCorrectAddress).toBeTruthy();
const walletAccount = await blankPage.evaluate(
async ([currentAccount]) => {
const wallet = await window.fuel.getWallet(currentAccount);
return wallet.address.toString();
},
[currentAccount]
);
expect(Address.fromString(currentAccount).toString()).toEqual(
walletAccount
);
});

await test.step('window.fuel.accounts()', async () => {
Expand Down
16 changes: 11 additions & 5 deletions packages/app/playwright/e2e/Accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test.describe('New Accounts', () => {
await waitUrl(page, '/wallet');
await hasText(page, /Assets/i);
const address = data.accounts[1].address.toString();
await hasAriaLabel(page, Address.fromDynamicInput(address).toB256());
await hasAriaLabel(page, Address.fromDynamicInput(address).toString());
});

test('should be able to edit account name', async () => {
Expand Down Expand Up @@ -226,12 +226,18 @@ test.describe('Existing Accounts', () => {

// Checks
// saved wal 1 add account 1 = wal 3 add account 1
expect(wal1Account1).toBe(Address.fromDynamicInput(fuelAddress1).toB256());
expect(wal1Account1).toBe(
Address.fromDynamicInput(fuelAddress1).toString()
);
// saved wal 1 add account 2 = wal 3 add account 2
expect(wal1Account2).toBe(Address.fromDynamicInput(fuelAddress2).toB256());
expect(wal1Account2).toBe(
Address.fromDynamicInput(fuelAddress2).toString()
);
// saved wal 2 add account = wal 3 add account 3
expect(wal1Account3).toBe(Address.fromDynamicInput(fuelAddPriv).toB256());
expect(wal1Account3).toBe(Address.fromDynamicInput(fuelAddPriv).toString());
// saved wal 1 add account 3 = wal 3 add account 4
expect(wal1Account4).toBe(Address.fromDynamicInput(fuelAddress3).toB256());
expect(wal1Account4).toBe(
Address.fromDynamicInput(fuelAddress3).toString()
);
});
});
3 changes: 1 addition & 2 deletions packages/app/playwright/e2e/RecoverWallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Browser, Page } from '@playwright/test';
import test, { chromium, expect } from '@playwright/test';

import { Address } from 'fuels';
import {
getButtonByText,
getByAriaLabel,
Expand Down Expand Up @@ -62,7 +61,7 @@ test.describe('RecoverWallet', () => {
/** Account created */
await hasText(page, /Wallet created successfully/i);
await hasText(page, /Account 1/i);
await hasText(page, '0x1d23...e8e2');
await hasText(page, '0x1d23...E8E2');
});

test.describe('when pasting', () => {
Expand Down
Loading

0 comments on commit 8851681

Please sign in to comment.