Skip to content

Commit

Permalink
test: refactor LSP6 + LSP20 tests for ethers v6
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Feb 17, 2024
1 parent 1ade771 commit 3771bd4
Show file tree
Hide file tree
Showing 54 changed files with 2,901 additions and 2,739 deletions.
92 changes: 46 additions & 46 deletions tests/LSP20CallVerification/LSP20CallVerification.behaviour.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { ethers, network } from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { FakeContract, smock } from '@defi-wonderland/smock';

// types
Expand Down Expand Up @@ -46,8 +46,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
describe('when testing lsp20 integration', () => {
describe('when owner is an EOA', () => {
describe('when calling `setData(bytes32,bytes)`', () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

it('should pass when owner calls', async () => {
await context.universalProfile
Expand All @@ -67,8 +67,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

describe('when calling `setData(bytes32[],bytes[])` array', () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey2'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey2'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

it('should pass when owner calls', async () => {
await context.universalProfile
Expand Down Expand Up @@ -154,7 +154,7 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
it('should revert when the non-owner is calling', async () => {
const operationsType = [OPERATION_TYPES.CALL];
const recipients = [context.accounts[1].address];
const values = [ethers.BigNumber.from('0')];
const values = [ethers.toBigInt('0')];
const datas = ['0x'];

await expect(
Expand Down Expand Up @@ -191,15 +191,15 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

describe('when calling `renounceOwnership`', () => {
it('should pass when the owner is calling', async () => {
await network.provider.send('hardhat_mine', [ethers.utils.hexValue(500)]);
await network.provider.send('hardhat_mine', [ethers.toQuantity(500)]);

await expect(
context.universalProfile.connect(context.deployParams.owner).renounceOwnership(),
).to.emit(context.universalProfile, 'RenounceOwnershipStarted');
});

it('should revert when the non-owner is calling', async () => {
await network.provider.send('hardhat_mine', [ethers.utils.hexValue(100)]);
await network.provider.send('hardhat_mine', [ethers.toQuantity(100)]);

await expect(context.universalProfile.connect(context.accounts[3]).renounceOwnership())
.to.be.revertedWithCustomError(context.universalProfile, 'LSP20EOACannotVerifyCall')
Expand All @@ -211,12 +211,12 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

before('Use custom owner that implements LSP1', async () => {
newContractOwner = await new OwnerWithURD__factory(context.accounts[0]).deploy(
context.universalProfile.address,
await context.universalProfile.getAddress(),
);

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(newContractOwner.address);
.transferOwnership(await newContractOwner.getAddress());

await newContractOwner.acceptOwnership();
});
Expand All @@ -228,7 +228,7 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
it('should renounce ownership of the contract and call the URD of the previous owner', async () => {
await context.universalProfile.connect(context.accounts[0]).renounceOwnership();

await network.provider.send('hardhat_mine', [ethers.utils.hexValue(199)]);
await network.provider.send('hardhat_mine', [ethers.toQuantity(199)]);

const tx = await context.universalProfile
.connect(context.accounts[0])
Expand All @@ -237,12 +237,12 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
await expect(tx)
.to.emit(newContractOwner, 'UniversalReceiver')
.withArgs(
context.universalProfile.address,
await context.universalProfile.getAddress(),
0,
LSP1_TYPE_IDS.LSP0OwnershipTransferred_SenderNotification,
abiCoder.encode(
['address', 'address'],
[newContractOwner.address, ethers.constants.AddressZero],
[await newContractOwner.getAddress(), ethers.ZeroAddress],
),
'0x',
);
Expand All @@ -262,11 +262,11 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(ownerContract.address);
.transferOwnership(await ownerContract.getAddress());

await ownerContract
.connect(context.deployParams.owner)
.acceptOwnership(context.universalProfile.address);
.acceptOwnership(await context.universalProfile.getAddress());
});

after('reverting to previous owner', async () => {
Expand All @@ -278,8 +278,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should revert when calling LSP0 function', async () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

await expect(context.universalProfile.setData(dataKey, dataValue))
.to.be.revertedWithCustomError(context.universalProfile, 'LSP20CallingVerifierFailed')
Expand All @@ -297,9 +297,9 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(ownerContract.address);
.transferOwnership(await ownerContract.getAddress());

await ownerContract.acceptOwnership(context.universalProfile.address);
await ownerContract.acceptOwnership(await context.universalProfile.getAddress());
});

after('reverting to previous owner', async () => {
Expand All @@ -311,8 +311,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should revert when calling LSP0 function', async () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

await expect(
context.universalProfile.setData(dataKey, dataValue),
Expand All @@ -330,9 +330,9 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(ownerContract.address);
.transferOwnership(await ownerContract.getAddress());

await ownerContract.acceptOwnership(context.universalProfile.address);
await ownerContract.acceptOwnership(await context.universalProfile.getAddress());
});

after('reverting to previous owner', async () => {
Expand All @@ -344,8 +344,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling LSP0 function', async () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

await expect(context.universalProfile.setData(dataKey, dataValue)).to.emit(
ownerContract,
Expand All @@ -364,9 +364,9 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(ownerContract.address);
.transferOwnership(await ownerContract.getAddress());

await ownerContract.acceptOwnership(context.universalProfile.address);
await ownerContract.acceptOwnership(await context.universalProfile.getAddress());
});

after('reverting to previous owner', async () => {
Expand All @@ -378,8 +378,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should revert when calling `setData(bytes32,bytes)`', async () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

await expect(
context.universalProfile.setData(dataKey, dataValue),
Expand All @@ -397,9 +397,9 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte

await context.universalProfile
.connect(context.deployParams.owner)
.transferOwnership(ownerContract.address);
.transferOwnership(await ownerContract.getAddress());

await ownerContract.acceptOwnership(context.universalProfile.address);
await ownerContract.acceptOwnership(await context.universalProfile.getAddress());
});

after('reverting to previous owner', async () => {
Expand All @@ -411,8 +411,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should revert when calling `setData(bytes32,bytes)`', async () => {
const dataKey = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.utils.hexlify(ethers.utils.randomBytes(50));
const dataKey = ethers.keccak256(ethers.toUtf8Bytes('RandomKey1'));
const dataValue = ethers.hexlify(ethers.randomBytes(50));

await expect(context.universalProfile.setData(dataKey, dataValue))
.to.be.revertedWithCustomError(context.universalProfile, 'LSP20CallVerificationFailed')
Expand All @@ -436,8 +436,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(newUniversalProfile.connect(context.accounts[3]).setData(key, value))
.to.emit(newUniversalProfile, 'DataChanged')
Expand Down Expand Up @@ -467,8 +467,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(
newUniversalProfile.connect(context.accounts[3])['setData(bytes32,bytes)'](key, value),
Expand Down Expand Up @@ -500,8 +500,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(newUniversalProfile.connect(context.accounts[3]).setData(key, value))
.to.emit(newUniversalProfile, 'DataChanged')
Expand Down Expand Up @@ -537,8 +537,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(
newUniversalProfile.connect(context.accounts[3])['setData(bytes32,bytes)'](key, value),
Expand Down Expand Up @@ -568,8 +568,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should revert when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(
newUniversalProfile.connect(context.accounts[3]).setData(key, value),
Expand All @@ -587,7 +587,7 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
LSP20_SUCCESS_VALUES.VERIFY_CALL.WITH_POST_VERIFICATION,
);
secondCallReturnExpandedValueContract.lsp20VerifyCallResult.returns(
ethers.utils.solidityPack(
ethers.solidityPacked(
['bytes4', 'bytes28'],
[LSP20_SUCCESS_VALUES.VERIFY_CALL_RESULT, '0x' + '0'.repeat(56)],
),
Expand All @@ -599,8 +599,8 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
});

it('should pass when calling `setData(bytes32,bytes)`', async () => {
const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key'));
const value = ethers.utils.hexlify(ethers.utils.randomBytes(500));
const key = ethers.keccak256(ethers.toUtf8Bytes('My Key'));
const value = ethers.hexlify(ethers.randomBytes(500));

await expect(newUniversalProfile.connect(context.accounts[3]).setData(key, value))
.to.emit(newUniversalProfile, 'DataChanged')
Expand Down
Loading

0 comments on commit 3771bd4

Please sign in to comment.