Skip to content

Commit

Permalink
test: address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Oct 19, 2023
1 parent 1bcbe45 commit b0a9d46
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
19 changes: 14 additions & 5 deletions src/lib/classes/lsp8-identifiable-digital-asset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { lsp4DigitalAsset } from '../../../test/lsp4-digital-asset.mock';
import { JSONURL_KNOWN_HASH_FUNCTIONS } from '../helpers/config.helper';

import { ProxyDeployer } from './proxy-deployer';

Check failure on line 17 in src/lib/classes/lsp8-identifiable-digital-asset.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

There should be at least one empty line between import groups
import ERC725 from '@erc725/erc725.js';

Check failure on line 18 in src/lib/classes/lsp8-identifiable-digital-asset.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

`@erc725/erc725.js` import should occur before import of `@lukso/lsp-smart-contracts`

Check failure on line 18 in src/lib/classes/lsp8-identifiable-digital-asset.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'ERC725' is defined but never used

jest.setTimeout(30000);
jest.useRealTimers();
Expand Down Expand Up @@ -120,6 +121,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
}
);
});

it('Should be compatible with RxJS', (done) => {
const myLSPFactory = new LSPFactory(provider, signer);
let lsp8Address: string;
Expand Down Expand Up @@ -287,6 +289,7 @@ describe('LSP8IdentifiableDigitalAsset', () => {
signer
);
});

it('should deploy and set LSP4DigitalAsset data', async () => {
const ownerAddress = await digitalAsset.owner();
expect(ownerAddress).toEqual(controllerAddress);
Expand All @@ -296,14 +299,20 @@ describe('LSP8IdentifiableDigitalAsset', () => {
expect(data.startsWith(JSONURL_KNOWN_HASH_FUNCTIONS['keccak256(utf8)'])).toBe(true);
expect(data).toEqual(expectedLSP4Value);
});
it('should have correct name and symbol set', async () => {
const [retrievedName, retrievedSymbol] = await digitalAsset.getDataBatch([
'0xdeba1e292f8ba88238e10ab3c7f88bd4be4fac56cad5194b6ecceaf653468af1',
'0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756',
]);

it('should have correct name, symbol and token ID type set', async () => {
const [retrievedName, retrievedSymbol, retrievedTokenIdType] =
await digitalAsset.getDataBatch([
ERC725YDataKeys.LSP4.LSP4TokenName,
ERC725YDataKeys.LSP4.LSP4TokenSymbol,
ERC725YDataKeys.LSP8.LSP8TokenIdType,
]);

const tokenIdTypeDecoded = ethers.BigNumber.from(retrievedTokenIdType).toNumber();

expect(ethers.utils.toUtf8String(retrievedName)).toEqual(name);
expect(ethers.utils.toUtf8String(retrievedSymbol)).toEqual(symbol);
expect(tokenIdTypeDecoded).toEqual(tokenIdType);
});
});

Expand Down
13 changes: 7 additions & 6 deletions src/lib/classes/proxy-deployer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ERC725YDataKeys } from '@lukso/lsp-smart-contracts';
import { ethers, SignerWithAddress } from 'hardhat';
import { hexlify, randomBytes } from 'ethers/lib/utils';

Check failure on line 2 in src/lib/classes/proxy-deployer.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

`ethers/lib/utils` import should occur before import of `hardhat`

import { ProxyDeployer } from './proxy-deployer';

Expand All @@ -17,18 +17,19 @@ describe('UniversalProfile', () => {
baseContracts = await proxyDeployer.deployUniversalProfileBaseContracts();
});

it('should deploy the ERC725Account proxy and setData', async () => {
it('should deploy the ERC725Account proxy and be able to set any data key/value pair', async () => {
// LSPAccount
const erc725AccountProxy = await proxyDeployer.deployProxyContract(
baseContracts.universalProfile
);
await erc725AccountProxy.initialize(await signer.getAddress());

await erc725AccountProxy.setData(ERC725YDataKeys.LSP3.LSP3Profile, '0xbeefbeef', {
const randomDataKey = hexlify(randomBytes(32));
const randomDataValueExpected = hexlify(randomBytes(4));

await erc725AccountProxy.setData(randomDataKey, randomDataValueExpected, {
from: await signer.getAddress(),
});
const data = await erc725AccountProxy.getData(ERC725YDataKeys.LSP3.LSP3Profile);

expect(data).toEqual('0xbeefbeef');
expect(await erc725AccountProxy.getData(randomDataKey)).toEqual(randomDataValueExpected);
});
});
24 changes: 11 additions & 13 deletions src/lib/classes/universal-profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('UniversalProfile', () => {
expect(signerPermissions).toEqual(ALL_PERMISSIONS);
});

it('signer address should have no permissions set', async () => {
it('random signer address should have no permissions set', async () => {
const signerPermissions = await universalProfile.getData(
ERC725YDataKeys.LSP6['AddressPermissions:Permissions'] + signers[0].address.substring(2)
);
Expand Down Expand Up @@ -180,6 +180,7 @@ describe('UniversalProfile', () => {
let keyManager;
let firstControllerAddress: string;
let secondControllerAddress: string;

const customPermissions = ERC725.encodePermissions({
DELEGATECALL: true,
CALL: true,
Expand Down Expand Up @@ -210,12 +211,9 @@ describe('UniversalProfile', () => {
});

it('1st address should have ALL_PERMISSIONS set', async () => {
const signerPermissions = await universalProfile
.connect(signers[0])
.getData(
ERC725YDataKeys.LSP6['AddressPermissions:Permissions'] +
firstControllerAddress.substring(2)
);
const signerPermissions = await universalProfile.getData(
ERC725YDataKeys.LSP6['AddressPermissions:Permissions'] + firstControllerAddress.substring(2)
);

expect(signerPermissions).toEqual(ALL_PERMISSIONS);
});
Expand All @@ -226,7 +224,7 @@ describe('UniversalProfile', () => {
ERC725YDataKeys.LSP6['AddressPermissions[]'].index +
ethers.utils.hexZeroPad(hexIndex, 16).substring(2);

const result = await universalProfile.connect(signers[0]).callStatic.getData(key);
const result = await universalProfile.getData(key);
const checkedsumResult = ethers.utils.getAddress(result);
expect(checkedsumResult).toEqual(firstControllerAddress);
});
Expand All @@ -248,7 +246,7 @@ describe('UniversalProfile', () => {
ERC725YDataKeys.LSP6['AddressPermissions[]'].index +
ethers.utils.hexZeroPad(hexIndex, 16).substring(2);

const result = await universalProfile.connect(signers[0]).getData(key);
const result = await universalProfile.getData(key);
const checkedsumResult = ethers.utils.getAddress(result);
expect(checkedsumResult).toEqual(secondControllerAddress);
});
Expand Down Expand Up @@ -622,11 +620,11 @@ describe('UniversalProfile', () => {
signers[0]
);

const data = await universalProfile.getData(
const universalReceiverDelegateAddress = await universalProfile.getData(
ERC725YDataKeys.LSP1.LSP1UniversalReceiverDelegate
);

const checkedsumResult = ethers.utils.getAddress(data);
const checkedsumResult = ethers.utils.getAddress(universalReceiverDelegateAddress);

expect(checkedsumResult).toEqual(baseContracts.universalReceiverDelegate.address);
});
Expand All @@ -652,11 +650,11 @@ describe('UniversalProfile', () => {
signers[0]
);

const univeralReceiverDelegate = await universalProfile.getData(
const universalReceiverDelegateAddress = await universalProfile.getData(
ERC725YDataKeys.LSP1.LSP1UniversalReceiverDelegate
);

const checkedsumResult = ethers.utils.getAddress(univeralReceiverDelegate);
const checkedsumResult = ethers.utils.getAddress(universalReceiverDelegateAddress);

expect(checkedsumResult).toEqual(deployedContracts.LSP1UniversalReceiverDelegate.address);
});
Expand Down

0 comments on commit b0a9d46

Please sign in to comment.