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

Add evm function call #270

Merged
merged 69 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ba687de
Refactor to match new multichain tools interface
Pessina Jun 25, 2024
682c50a
Fix typescript errors
Pessina Jun 25, 2024
b288cea
Improve fast-auth-wallet types
Pessina Jun 26, 2024
2188e43
Roll back yarn lock
Pessina Jun 26, 2024
4a94035
Fix imports
Pessina Jun 26, 2024
6a29c94
Fix validation
Pessina Jun 26, 2024
c107a34
Fix BNB fee and simplify logic to get Asset Metadata
Pessina Jun 27, 2024
b344e63
Use SendMultiChainMessage instead of ChainDetails on get asset metada…
Pessina Jun 27, 2024
6b32fb7
Add sync comment on SignMultichainMessage type
Pessina Jun 27, 2024
f2cf1a9
Remove unused packages
Pessina Jun 27, 2024
39751d7
Add wallet on beta version and fix types
Pessina Jun 27, 2024
5ad56a0
Fix multichain tests
Pessina Jun 27, 2024
3f7e44a
Update sign transaction with new wallet interface
Pessina Jun 27, 2024
18c41e3
Add test for FunctionCall
Pessina Jun 28, 2024
c085798
Remove unused variable
Pessina Jun 28, 2024
a68dfa2
Remove only from MultiChain test
Pessina Jul 4, 2024
72fdd84
Add new packages
Pessina Jul 4, 2024
9c7261b
Add EVM FunctionCall to iFrame interface
Pessina Jul 15, 2024
a9c2529
Remove unused methods and make callContractWithDataField more flexible
Pessina Jul 15, 2024
6296b72
Include all derived addresses for johndoe12.testnet
Pessina Jul 15, 2024
09870c7
Add tests for EVM FunctionCall
Pessina Jul 15, 2024
f17be10
Re-use constant derive address on faucets
Pessina Jul 15, 2024
0a0ed58
Clean up code
Pessina Jul 15, 2024
459a495
Skip EVM function call tests as it will hit the Infura limit
Pessina Jul 15, 2024
07c99b7
Remove unused code
Pessina Jul 15, 2024
322e667
Fix overflow and rename constant
Pessina Jul 15, 2024
0acdc02
Include from on EVM fee estimation transaction
Pessina Jul 15, 2024
93445c8
Deployment with ethers on local hardhat network working
Pessina Jul 16, 2024
f36d717
Add hardhat to e2e workspace and deploy contract from testset
Pessina Jul 16, 2024
8cdafa2
Add CHAIN_CONFIG to getMultichainAssetInfo
Pessina Jul 16, 2024
d515701
Include new field to choose using local rpc
Pessina Jul 16, 2024
32db86d
Fix nonce issue by creating one account per test
Pessina Jul 16, 2024
8e05009
Include command to run hardhat server
Pessina Jul 16, 2024
41b6262
Fix BTC wrong chainConfig
Pessina Jul 18, 2024
4ab3919
Display error on iFrame instead of closing it and returning
Pessina Jul 18, 2024
a4b8c3c
Allow to use local/real RPC
Pessina Jul 18, 2024
5768130
Fix closeModal function
Pessina Jul 19, 2024
a498c95
Fix invalid forms submission on safari
Pessina Jul 19, 2024
63c7be1
Revert to production config
Pessina Jul 19, 2024
c239818
Remove hardcoded rpc urls
Pessina Jul 19, 2024
18d4fbe
Update the tests to run most common failing tests separated
Pessina Jul 19, 2024
dcce727
DRY playwright.yml
Pessina Jul 19, 2024
bff18f3
Fix servers initialization
Pessina Jul 19, 2024
577d6da
Matrix run in sequence
Pessina Jul 19, 2024
85ad47d
Fix command
Pessina Jul 19, 2024
f911888
Fix alignment
Pessina Jul 19, 2024
66e9b5a
Remove useless server start
Pessina Jul 19, 2024
460e3e2
Rename and reorder the tests
Pessina Jul 19, 2024
2d95a94
Fix hardhat start url
Pessina Jul 23, 2024
661bd34
update yarn.lock
Pessina Jul 23, 2024
d3b1029
Update to new multichain-tools package with nonce error handling and …
Pessina Jul 23, 2024
99ca26e
Update comment
Pessina Jul 23, 2024
160875f
Remove test.only
Pessina Jul 23, 2024
3f6f58c
Update multichain-tools version and fix but on amount validation
Pessina Jul 23, 2024
62d392b
Remove nonce retry for evm
Pessina Jul 23, 2024
eedf696
Add key rotation on multichain signature to avoid nonce issues
Pessina Jul 24, 2024
01e2e94
Update playwright variables
Pessina Jul 24, 2024
7ebf669
Re-add testAccounts.json
Pessina Jul 24, 2024
c75ff41
Update to use contract v5
Pessina Jul 24, 2024
787f615
Update Unknown key address
Pessina Jul 24, 2024
40b302a
Add correct EVM_DOMAIN key
Pessina Jul 24, 2024
f8416eb
Merge remote-tracking branch 'origin/main' into add-evm-function-call
Pessina Jul 25, 2024
db52750
Update playwright file
Pessina Jul 25, 2024
972d21e
Upgrade versions and fix types
Pessina Aug 25, 2024
eafbd0d
Merge remote-tracking branch 'origin/main' into add-evm-function-call
Pessina Aug 25, 2024
e515578
Upgrade packages and contract
Pessina Aug 25, 2024
30c7380
Reduce project to avoid concurrency issues
Pessina Aug 25, 2024
0e0f5f8
PR comments
Pessina Aug 28, 2024
39ea0a5
Add chainId validation
Pessina Sep 1, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ jobs:
MULTICHAIN_TEST_ACCOUNT_ID: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_ID }}
MULTICHAIN_TEST_ACCOUNT_FAK: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_FAK }}
MULTICHAIN_TEST_ACCOUNT_LAK: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_LAK }}
MULTICHAIN_TEST_ACCOUNT_ID_2: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_ID_2 }}
MULTICHAIN_TEST_ACCOUNT_FAK_2: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_FAK_2 }}
MULTICHAIN_TEST_ACCOUNT_ID_3: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_ID_3 }}
MULTICHAIN_TEST_ACCOUNT_FAK_3: ${{ secrets.MULTICHAIN_TEST_ACCOUNT_FAK_3 }}
ETH_PROVIDER_URL_TESTNET: ${{ secrets.ETH_PROVIDER_URL_TESTNET }}
BNB_PROVIDER_URL_TESTNET: ${{ secrets.BNB_PROVIDER_URL_TESTNET }}
BTC_PROVIDER_URL_TESTNET: ${{ secrets.BTC_PROVIDER_URL_TESTNET }}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "yarn && yarn workspace near-fast-auth-signer-e2e-tests test"
"test": "yarn && yarn workspace near-fast-auth-signer-e2e-tests test",
"test:multichain-testnet": "yarn && yarn workspace near-fast-auth-signer-e2e-tests test:multichain-testnet",
"test:multichain-local": "yarn && yarn workspace near-fast-auth-signer-e2e-tests test:multichain-local",
"test:remaining": "yarn && yarn workspace near-fast-auth-signer-e2e-tests test:remaining"
},
"devDependencies": {
"@types/node": "^20.9.0",
Expand Down
15 changes: 15 additions & 0 deletions packages/near-fast-auth-signer-e2e-tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ yarn-error.log*
/playwright-report/
/blob-report/
/playwright/.cache/

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
92 changes: 92 additions & 0 deletions packages/near-fast-auth-signer-e2e-tests/contracts/FT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Origal repo: https://github.com/Consensys/Tokens/blob/master/contracts/eip20/EIP20.sol
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this file is extended version of file from above link? could you add a bit more detail about what has modified/extended and why? (eg. I notice that mint doesn't exist on above, but added below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't added any explanation because we will never change this file again. It's just a contract implementing the ERC20 interface for testing.

The code here was copy pasted from the URL linked, and the mint function was added so we can distribute the tokens as we want for testing.

I was checking other options to implement this contracts, looks like Open Zeppelin haves a npm package with the implementations for all we need ERC20, ERC721, ERC1155.

But if it's ok I would like to tackle this in another PR, there is too much work here already.

That's the package I'm looking to use: https://www.npmjs.com/package/@openzeppelin/contracts


pragma solidity ^0.8.24;

interface EIP20Interface {
function totalSupply() external view returns (uint256);
function balanceOf(address _owner) external view returns (uint256 balance);
function transfer(address _to, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint256 remaining);
function mint(address _to, uint256 _amount) external returns (bool success);

event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract EIP20 is EIP20Interface {

uint256 constant private MAX_UINT256 = type(uint256).max;
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;
string public name;
uint8 public decimals;
string public symbol;
uint256 private _totalSupply;

constructor(
uint256 _initialAmount,
string memory _tokenName,
uint8 _decimalUnits,
string memory _tokenSymbol
) {
balances[msg.sender] = _initialAmount;
_totalSupply = _initialAmount;
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
}

function totalSupply() external view override returns (uint256) {
return _totalSupply;
}

function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}

function transfer(address _to, uint256 _value) public override returns (bool success) {
require(balances[msg.sender] >= _value, "Insufficient balance");
unchecked {
balances[msg.sender] -= _value;
balances[_to] += _value;
}
emit Transfer(msg.sender, _to, _value);
return true;
}

function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {
uint256 currentAllowance = allowed[_from][msg.sender];
require(balances[_from] >= _value && currentAllowance >= _value, "Insufficient balance or allowance");
unchecked {
balances[_to] += _value;
balances[_from] -= _value;
if (currentAllowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
}
emit Transfer(_from, _to, _value);
return true;
}

function approve(address _spender, uint256 _value) public override returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}

function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}

function mint(address _to, uint256 _amount) external override returns (bool success) {
require(_to != address(0), "ERC20: mint to the zero address");
_totalSupply += _amount;
unchecked {
balances[_to] += _amount;
}
emit Transfer(address(0), _to, _amount);
return true;
}
}
13 changes: 13 additions & 0 deletions packages/near-fast-auth-signer-e2e-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('@nomicfoundation/hardhat-toolbox');

const config = {
solidity: '0.8.24',
networks: {
hardhat: {
port: 8545,
chainId: 11155111,
}
}
};

module.exports = config;
35 changes: 28 additions & 7 deletions packages/near-fast-auth-signer-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
],
"scripts": {
"test": "yarn playwright test",
"start": "webpack serve --mode development --history-api-fallback"
"test:multichain-testnet": "yarn playwright test --grep @multichain-testnet",
"test:multichain-local": "yarn playwright test --grep @multichain-local",
"test:remaining": "yarn playwright test --grep-invert \"@multichain-testnet|@multichain-local\"",
"start": "webpack serve --mode development --history-api-fallback",
"start:hardhat": "hardhat compile && hardhat node"
},
"dependencies": {
"@near-js/crypto": "^1.2.3",
Expand All @@ -23,16 +27,16 @@
"@near-wallet-selector/core": "8.7.0",
"bitcoinjs-lib": "^6.1.5",
"borsh": "0.7.0",
"canonicalize": "^2.0.0",
"ethers": "^6.13.1",
"firebase-admin": "^12.1.0",
"fs-extra": "^11.2.0",
"https-browserify": "^1.0.0",
"js-sha256": "^0.11.0",
"mailpop3": "^0.1.0",
"multichain-tools": "^1.0.12",
"multichain-tools": "2.0.14-beta.10",
"near-api-js": "^2.1.4",
"near-fast-auth-signer": "*",
"near-fastauth-wallet": "^0.0.17",
"near-fastauth-wallet": "2.0.2-beta.10",
"process": "^0.11.10",
"proper-lockfile": "^4.1.2",
"react": "^18.2.0",
Expand All @@ -46,14 +50,31 @@
"devDependencies": {
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ignition": "^0.15.0",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@playwright/test": "^1.44.0",
"@types/node": "^20.9.0",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@types/uuid": "^9.0.8",
"chai": "^4.2.0",
"ethers": "^6.4.0",
"hardhat": "^2.14.0",
"hardhat-gas-reporter": "^1.0.8",
"playwright": "^1.44.0",
"ts-node": "^10.9.2",
"solidity-coverage": "^0.8.0",
"ts-node": ">=8.0.0",
"typechain": "^8.3.0",
"typescript": ">=4.5.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"private": true
}
}
54 changes: 30 additions & 24 deletions packages/near-fast-auth-signer-e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,40 @@ export default defineConfig<TestOptions>({
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
],

/* Run your local dev serve`r` before starting the tests */
webServer: [
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
command: 'cd ../near-fast-auth-signer && NETWORK_ID=testnet yarn run start:test',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] },
command: 'yarn run start:hardhat',
url: 'http://127.0.0.1:8545',
reuseExistingServer: !process.env.CI,
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
},
],

/* Run your local dev serve`r` before starting the tests */
webServer: [{
command: 'cd ../near-fast-auth-signer && NETWORK_ID=testnet yarn run start:test',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
{
command: 'yarn run start',
url: 'http://127.0.0.1:3001',
reuseExistingServer: !process.env.CI,
}
command: 'yarn run start',
url: 'http://127.0.0.1:3001',
reuseExistingServer: !process.env.CI,
}
],
});
12 changes: 8 additions & 4 deletions packages/near-fast-auth-signer-e2e-tests/scripts/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { derivedAddresses } from '../utils/constants';

const { ethers } = require('ethers');

interface WalletInfo {
Expand Down Expand Up @@ -83,9 +85,11 @@ async function requestTokensFromFaucet(wallets: WalletInfo[]): Promise<void> {
}
}

const wallets: WalletInfo[] = [
{ address: '0xf64750f13f75fb9e2f4d9fd98ab72d742d1e33eb', chain: 'eth' },
{ address: '0x81d205120a9f04d3f1ce733c5ed0a0bc66714c71', chain: 'bnb' }
export const walletsAddresses: WalletInfo[] = [
{ address: derivedAddresses.EVM_PERSONAL, chain: 'eth' },
{ address: derivedAddresses.EVM_PERSONAL_2, chain: 'eth' },
{ address: derivedAddresses.EVM_PERSONAL_3, chain: 'eth' },
{ address: derivedAddresses.EVM_DOMAIN, chain: 'bnb' }
];

requestTokensFromFaucet(wallets);
requestTokensFromFaucet(walletsAddresses);
34 changes: 15 additions & 19 deletions packages/near-fast-auth-signer-e2e-tests/test-app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { SignMessageParams } from '@near-wallet-selector/core';
import { Account, SignMessageParams } from '@near-wallet-selector/core';
import { FastAuthWallet } from 'near-fastauth-wallet';
import React, { useEffect, useState } from 'react';

import SignMultiChain, { TransactionFormValues } from './components/SignMultiChain';
import SignMultiChain from './components/SignMultiChain';
import useWalletSelector from './hooks/useWalletSelector';
import {
getTransactionPayload,
} from '../utils/multiChain';

type FastAuthWalletInterface = Awaited<ReturnType<typeof FastAuthWallet>>;

export default function App() {
const selectorInstance = useWalletSelector();
const [fastAuthWallet, setFastAuthWallet] = useState<any>();
const [accounts, setAccounts] = useState<any[] | undefined>(undefined);
const [fastAuthWallet, setFastAuthWallet] = useState<FastAuthWalletInterface | null>(null);
const [accounts, setAccounts] = useState<Account[] | undefined>(undefined);
const [isMessageSignatureValid, setIsMessageSignatureValid] = useState(false);

useEffect(() => {
const getWallet = async () => {
if (!selectorInstance) return;

const wallet = await selectorInstance.wallet('fast-auth-wallet');
setFastAuthWallet(wallet);
// Using any because the selector exposes the NEP wallet interface that cannot be cast to the current FastAuthWallet interface
setFastAuthWallet(wallet as any);
};

getWallet();
Expand Down Expand Up @@ -64,19 +65,15 @@ export default function App() {
try {
setIsMessageSignatureValid(false);
const messageSignature = await fastAuthWallet.signMessage(signMessageParams);
const isValid = await fastAuthWallet.verifySignMessage(signMessageParams, messageSignature);
setIsMessageSignatureValid(isValid);
if (messageSignature) {
const isValid = await fastAuthWallet.verifySignMessage(signMessageParams, messageSignature);
setIsMessageSignatureValid(isValid);
}
} catch (error) {
console.error('Error signing message:', error);
}
};

const handleSubmitTransaction = async (values: TransactionFormValues) => {
const accountId = JSON.parse(window.localStorage.accountId);
const payload = await getTransactionPayload({ ...values, accountId });
await fastAuthWallet.signMultiChainTransaction(payload);
};

if (!selectorInstance || !fastAuthWallet || accounts === undefined) {
return (
<div id="loading-ws">Loading...</div>
Expand All @@ -89,7 +86,6 @@ export default function App() {
<button type="button" onClick={handleSignUp}>
Create Account
</button>

{accounts.length > 0 ? (
<div>
<button type="button" onClick={handleSignOut}>
Expand All @@ -102,13 +98,13 @@ export default function App() {
Sign In
</button>
)}
<SignMultiChain onSubmitForm={handleSubmitTransaction} />
<SignMultiChain />
<button
type="button"
data-testid="sign-transaction-button"
onClick={() => {
fastAuthWallet
.signAndSendTransaction(
.signAndSendDelegateAction(
JSON.parse(window.localStorage.transactionData)
);
}}
Expand Down
Loading
Loading