Skip to content
Open
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
66 changes: 33 additions & 33 deletions packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import eip712 from '../../vendor-js/eth-eip712-util/index.cjs';
import { WalletLinkSigner } from './WalletLinkSigner.js';
import { WalletLinkRelay } from './relay/WalletLinkRelay.js';
import { LOCAL_STORAGE_ADDRESSES_KEY } from './relay/constants.js';
import { MOCK_ADDERESS, MOCK_SIGNED_TX, MOCK_TX, MOCK_TYPED_DATA } from './relay/mocks/fixtures.js';
import { MOCK_ADDRESS, MOCK_SIGNED_TX, MOCK_TX, MOCK_TYPED_DATA } from './relay/mocks/fixtures.js';
import { mockedWalletLinkRelay } from './relay/mocks/relay.js';

vi.mock('./relay/WalletLinkRelay', () => {
Expand Down Expand Up @@ -41,7 +41,7 @@ vi.mock('./relay/WalletLinkRelay', () => {
}),
requestEthereumAccounts: vi.fn().mockResolvedValue({
method: 'requestEthereumAccounts',
result: [MOCK_ADDERESS],
result: [MOCK_ADDRESS],
}),
signAndSubmitEthereumTransaction: vi.fn().mockResolvedValue({
method: 'signAndSubmitEthereumTransaction',
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('LegacyProvider', () => {
it('handles enabling the provider successfully', async () => {
const provider = createAdapter();
const response = (await provider.request({ method: 'eth_requestAccounts' })) as Address[];
expect(response[0]).toBe(MOCK_ADDERESS.toLowerCase());
expect(response[0]).toBe(MOCK_ADDRESS.toLowerCase());
expect(mockCallback).toHaveBeenCalledWith('connect', { chainId: '0x1' });
});

Expand All @@ -107,7 +107,7 @@ describe('LegacyProvider', () => {
const response = (await provider.request({
method: 'eth_requestAccounts',
})) as Address[];
expect(response[0]).toBe(MOCK_ADDERESS.toLowerCase());
expect(response[0]).toBe(MOCK_ADDRESS.toLowerCase());
});

it("does NOT update the providers address on a postMessage's 'addressesChanged' event", () => {
Expand Down Expand Up @@ -143,30 +143,30 @@ describe('LegacyProvider', () => {
const response1 = (await provider.request({
method: 'eth_requestAccounts',
})) as Address[];
expect(response1[0]).toBe(MOCK_ADDERESS.toLowerCase());
expect(response1[0]).toBe(MOCK_ADDRESS.toLowerCase());

// @ts-expect-error accessing private value for test
expect(provider._addresses).toEqual([MOCK_ADDERESS.toLowerCase()]);
expect(provider._addresses).toEqual([MOCK_ADDRESS.toLowerCase()]);

// Set the account on the first request
const response2 = (await provider.request({
method: 'eth_requestAccounts',
})) as Address[];
expect(response2[0]).toBe(MOCK_ADDERESS.toLowerCase());
expect(response2[0]).toBe(MOCK_ADDRESS.toLowerCase());
});

it('gets the users address from storage on init', async () => {
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDERESS.toLowerCase());
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDRESS.toLowerCase());
const provider = createAdapter();

// @ts-expect-error accessing private value for test
expect(provider._addresses).toEqual([MOCK_ADDERESS.toLowerCase()]);
expect(provider._addresses).toEqual([MOCK_ADDRESS.toLowerCase()]);

// Set the account on the first request
const response = (await provider.request({
method: 'eth_requestAccounts',
})) as Address[];
expect(response[0]).toBe(MOCK_ADDERESS.toLowerCase());
expect(response[0]).toBe(MOCK_ADDRESS.toLowerCase());
});

describe('ecRecover', () => {
Expand All @@ -176,7 +176,7 @@ describe('LegacyProvider', () => {

beforeEach(() => {
sendRequestSpy.mockResolvedValue({
result: MOCK_ADDERESS,
result: MOCK_ADDRESS,
});
});

Expand All @@ -193,7 +193,7 @@ describe('LegacyProvider', () => {
signature: '0x',
},
});
expect(response).toBe(MOCK_ADDERESS);
expect(response).toBe(MOCK_ADDRESS);
});

test('personal_ecRecover', async () => {
Expand All @@ -209,12 +209,12 @@ describe('LegacyProvider', () => {
signature: '0x',
},
});
expect(response).toBe(MOCK_ADDERESS);
expect(response).toBe(MOCK_ADDRESS);
});
});

describe('personal_sign', () => {
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDERESS);
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDRESS);
const relay = mockedWalletLinkRelay();
const provider = createAdapter({ relay });

Expand All @@ -224,12 +224,12 @@ describe('LegacyProvider', () => {
});
const response = await provider?.request({
method: 'personal_sign',
params: ['My secret message', MOCK_ADDERESS],
params: ['My secret message', MOCK_ADDRESS],
});
expect(sendRequestSpy).toBeCalledWith({
method: 'signEthereumMessage',
params: {
address: MOCK_ADDERESS.toLowerCase(),
address: MOCK_ADDRESS.toLowerCase(),
message: '0x4d7920736563726574206d657373616765',
addPrefix: true,
typedDataJson: null,
Expand All @@ -252,7 +252,7 @@ describe('LegacyProvider', () => {
});

describe('signTypedData', () => {
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDERESS);
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDRESS);
const relay = mockedWalletLinkRelay();
const sendRequestSpy = vi.spyOn(relay, 'sendRequest');
const provider = createAdapter({ relay });
Expand All @@ -271,13 +271,13 @@ describe('LegacyProvider', () => {
const hashSpy = vi.spyOn(eip712, 'hashForSignTypedDataLegacy');
const response = await provider?.request({
method: 'eth_signTypedData_v1',
params: [[MOCK_TYPED_DATA], MOCK_ADDERESS],
params: [[MOCK_TYPED_DATA], MOCK_ADDRESS],
});
expect(hashSpy).toHaveBeenCalled();
expect(sendRequestSpy).toBeCalledWith({
method: 'signEthereumMessage',
params: {
address: MOCK_ADDERESS.toLowerCase(),
address: MOCK_ADDRESS.toLowerCase(),
message: ENCODED_MESSAGE,
addPrefix: false,
typedDataJson: ENCODED_TYPED_DATA_JSON,
Expand All @@ -290,13 +290,13 @@ describe('LegacyProvider', () => {
const hashSpy = vi.spyOn(eip712, 'hashForSignTypedData_v3');
const response = await provider?.request({
method: 'eth_signTypedData_v3',
params: [MOCK_ADDERESS, MOCK_TYPED_DATA],
params: [MOCK_ADDRESS, MOCK_TYPED_DATA],
});
expect(hashSpy).toHaveBeenCalled();
expect(sendRequestSpy).toBeCalledWith({
method: 'signEthereumMessage',
params: {
address: MOCK_ADDERESS.toLowerCase(),
address: MOCK_ADDRESS.toLowerCase(),
message: ENCODED_MESSAGE,
addPrefix: false,
typedDataJson: ENCODED_TYPED_DATA_JSON,
Expand All @@ -309,13 +309,13 @@ describe('LegacyProvider', () => {
const hashSpy = vi.spyOn(eip712, 'hashForSignTypedData_v4');
const response = await provider?.request({
method: 'eth_signTypedData_v4',
params: [MOCK_ADDERESS, MOCK_TYPED_DATA],
params: [MOCK_ADDRESS, MOCK_TYPED_DATA],
});
expect(hashSpy).toHaveBeenCalled();
expect(sendRequestSpy).toBeCalledWith({
method: 'signEthereumMessage',
params: {
address: MOCK_ADDERESS.toLowerCase(),
address: MOCK_ADDRESS.toLowerCase(),
message: ENCODED_MESSAGE,
addPrefix: false,
typedDataJson: ENCODED_TYPED_DATA_JSON,
Expand All @@ -328,13 +328,13 @@ describe('LegacyProvider', () => {
const hashSpy = vi.spyOn(eip712, 'hashForSignTypedData_v4');
const response = await provider?.request({
method: 'eth_signTypedData',
params: [MOCK_ADDERESS, MOCK_TYPED_DATA],
params: [MOCK_ADDRESS, MOCK_TYPED_DATA],
});
expect(hashSpy).toHaveBeenCalled();
expect(sendRequestSpy).toBeCalledWith({
method: 'signEthereumMessage',
params: {
address: MOCK_ADDERESS.toLowerCase(),
address: MOCK_ADDRESS.toLowerCase(),
message: ENCODED_MESSAGE,
addPrefix: false,
typedDataJson: ENCODED_TYPED_DATA_JSON,
Expand All @@ -347,7 +347,7 @@ describe('LegacyProvider', () => {
describe('RPC Methods', () => {
let provider: WalletLinkSigner | null = null;
beforeEach(() => {
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDERESS.toLowerCase());
testStorage.setItem(LOCAL_STORAGE_ADDRESSES_KEY, MOCK_ADDRESS.toLowerCase());
provider = createAdapter();
});

Expand All @@ -359,14 +359,14 @@ describe('LegacyProvider', () => {
const response = await provider?.request({
method: 'eth_accounts',
});
expect(response).toEqual([MOCK_ADDERESS.toLowerCase()]);
expect(response).toEqual([MOCK_ADDRESS.toLowerCase()]);
});

test('eth_coinbase', async () => {
const response = await provider?.request({
method: 'eth_coinbase',
});
expect(response).toBe(MOCK_ADDERESS.toLowerCase());
expect(response).toBe(MOCK_ADDRESS.toLowerCase());
});

test('net_version', async () => {
Expand All @@ -387,16 +387,16 @@ describe('LegacyProvider', () => {
const response = await provider?.request({
method: 'eth_requestAccounts',
});
expect(response).toEqual([MOCK_ADDERESS.toLowerCase()]);
expect(response).toEqual([MOCK_ADDRESS.toLowerCase()]);
});

test('eth_signTransaction', async () => {
const response = await provider?.request({
method: 'eth_signTransaction',
params: [
{
from: MOCK_ADDERESS,
to: MOCK_ADDERESS,
from: MOCK_ADDRESS,
to: MOCK_ADDRESS,
gasPrice: '21000',
maxFeePerGas: '10000000000',
maxPriorityFeePerGas: '10000000000',
Expand All @@ -423,8 +423,8 @@ describe('LegacyProvider', () => {
method: 'eth_sendTransaction',
params: [
{
from: MOCK_ADDERESS,
to: MOCK_ADDERESS,
from: MOCK_ADDRESS,
to: MOCK_ADDRESS,
gasPrice: '21000',
maxFeePerGas: '10000000000',
maxPriorityFeePerGas: '10000000000',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MOCK_ADDERESS = '0xFadAFCE89EA2221fa33005640Acf2C923312F2b9';
export const MOCK_ADDRESS = '0xFadAFCE89EA2221fa33005640Acf2C923312F2b9';

export const MOCK_TX = '0xc21a1aaace40a8ee9dd3827ae5a85412a05755cc004469efaf3cfdd82c59a670';

Expand Down Expand Up @@ -27,15 +27,15 @@ export const MOCK_TYPED_DATA = JSON.stringify({
name: 'Provider Test',
version: '1',
chainId: Number.parseInt('1', 10),
verifyingContract: MOCK_ADDERESS,
verifyingContract: MOCK_ADDRESS,
salt: '0xf2d857f4a3edcb9b78b4d503bfe733db1e3f6cdc2b7971ee739626c97e86a558',
},
primaryType: 'Bid',
message: {
amount: 100,
bidder: {
userId: 323,
wallet: MOCK_ADDERESS,
wallet: MOCK_ADDRESS,
},
},
});
6 changes: 3 additions & 3 deletions packages/wallet-sdk/src/sign/walletlink/relay/mocks/relay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HexString } from ':core/type/index.js';
import { Web3Response } from '../type/Web3Response.js';
import { WalletLinkRelay } from '../WalletLinkRelay.js';
import { MOCK_ADDERESS, MOCK_TX } from './fixtures.js';
import { HexString } from ':core/type/index.js';
import { MOCK_ADDRESS, MOCK_TX } from './fixtures.js';

export function mockedWalletLinkRelay(): WalletLinkRelay {
return mock as unknown as WalletLinkRelay;
Expand All @@ -16,7 +16,7 @@ const mock = {
requestEthereumAccounts() {
return makeMockReturn({
method: 'requestEthereumAccounts',
result: [MOCK_ADDERESS],
result: [MOCK_ADDRESS],
});
},
addEthereumChain() {
Expand Down