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

feat/PRO-2467/update-modular-modules-func #157

Merged
merged 2 commits into from
Jul 11, 2024
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [0.14.0] - 2024-07-10

### Added Changes
- Version update of `etherspot-modular`
- Added Etherspot Modular SDK `getAllModules` and `isModuleInstalled` to hook `useEtherspotModules`
- Updated `uninstallModule` with Etherspot Modular SDK `generateModuleDeInitData` to hook `useEtherspotModules` which allows to install and uninstall several modules

### Breaking Changes
- Updated `getAssets` which accepts optional props `chainId` and `name`

## [0.13.0] - 2024-06-17

### Added Changes
Expand Down
36 changes: 36 additions & 0 deletions __mocks__/@etherspot/modular-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ export class ModularSdk {
return userOpHash;
}

async generateModuleDeInitData() {
const deInitData = ethers.utils.defaultAbiCoder.encode(
["address", "bytes"],
['0x0000000000000000000000000000000000000001', '0x00']
);
return deInitData;
}

async installModule(moduleType, module, initData, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
throw new Error('No account address provided!')
Expand Down Expand Up @@ -132,6 +140,34 @@ export class ModularSdk {

return '0x456';
}

async getAllModules(pageSize, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
throw new Error('No account address provided!')
}

return {
validators: ['0x000', '0x111', '0x222']
};
}

async isModuleInstalled(moduleType, module, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
throw new Error('No account address provided!')
}

if (!moduleType || !module) {
throw new Error('uninstallModule props missing')
}

if (module === '0x111') {
return true;
}

if (module === '0x222') {
return false;
}
}
}

export const isWalletProvider = EtherspotModular.isWalletProvider;
Expand Down
57 changes: 50 additions & 7 deletions __tests__/hooks/useEtherspotModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const initData = ethers.utils.defaultAbiCoder.encode(
["address", "bytes"],
['0x0000000000000000000000000000000000000001', '0x00']
);
const deInitData = ethers.utils.defaultAbiCoder.encode(
["address", "bytes"],
['0x0000000000000000000000000000000000000001', '0x00']
);

describe('useEtherspotModules()', () => {
it('install one module', async () => {
Expand All @@ -31,7 +27,6 @@ describe('useEtherspotModules()', () => {
wrapper,
});


// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());

Expand Down Expand Up @@ -69,7 +64,7 @@ describe('useEtherspotModules()', () => {
// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());

const uninstallModuleNotInstalled = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, '0x222', deInitData)
const uninstallModuleNotInstalled = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, '0x222')
.catch((e) => {
console.error(e);
return `${e}`
Expand All @@ -88,8 +83,56 @@ describe('useEtherspotModules()', () => {
expect(uninstallModulePropsMissing).toBe('Error: Failed to uninstall module: Error: uninstallModule props missing');


const uninstallOneModule = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, moduleAddress, deInitData);
const uninstallOneModule = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, moduleAddress);
expect(uninstallOneModule).toBe('0x456');

});

it('list of modules for one wallet', async () => {
const wrapper = ({ children }) => (
<EtherspotTransactionKit provider={provider}>
{children}
</EtherspotTransactionKit>
);

const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
initialProps: { chainId: 1 },
wrapper,
});

// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());

const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
expect(installOneModule).toBe('0x123')

const listOfModules = await result.current.listModules();
expect(listOfModules.validators).toContain('0x111');
expect(listOfModules.validators).not.toContain('0x123');
});

it('isModule installed', async () => {
const wrapper = ({ children }) => (
<EtherspotTransactionKit provider={provider}>
{children}
</EtherspotTransactionKit>
);

const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
initialProps: { chainId: 1 },
wrapper,
});

// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());

const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
expect(installOneModule).toBe('0x123')

const isModuleOneInstalled = await result.current.isModuleInstalled(MODULE_TYPE.VALIDATOR, moduleAddress);
expect(isModuleOneInstalled).toBe(true);

const isModuleTowInstalled = await result.current.isModuleInstalled(MODULE_TYPE.VALIDATOR, '0x222');
expect(isModuleTowInstalled).toBe(false);
});
})
Loading
Loading