Skip to content

Commit

Permalink
added new modular functions, update getAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
RanaBug committed Jul 10, 2024
1 parent fdcb718 commit 3529b8c
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 82 deletions.
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
40 changes: 40 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,38 @@ export class ModularSdk {

return '0x456';
}

async getAllModules(pageSize, accountAddress) {
if (!pageSize) {
pageSize = 50
}

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
58 changes: 51 additions & 7 deletions __tests__/hooks/useEtherspotModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const initData = ethers.utils.defaultAbiCoder.encode(
["address", "bytes"],
['0x0000000000000000000000000000000000000001', '0x00']
);
const deInitData = ethers.utils.defaultAbiCoder.encode(
["address", "bytes"],
['0x0000000000000000000000000000000000000001', '0x00']
);
const deInitData = '0x00'

describe('useEtherspotModules()', () => {
it('install one module', async () => {
Expand All @@ -31,7 +28,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 +65,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 +84,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

0 comments on commit 3529b8c

Please sign in to comment.