From c0c9c2a6bfc660b2ae4863733dcfb8f67496bbed Mon Sep 17 00:00:00 2001 From: Yamen Merhi Date: Tue, 16 Nov 2021 11:18:57 +0200 Subject: [PATCH] URDelegate/test (#58) * test: Add token related const to `constants.ts` * test: remove seperate URD test for LSP7 & LSP8 * test: combine URD test for LSP7 & LSP8 + optimize --- .../LSP1UniversalReceiverDelegate.spec.ts | 1200 ++++++++++++++++ ...ersalReceiverDelegateForLSP7Assets.spec.ts | 1234 ----------------- ...ersalReceiverDelegateForLSP8Assets.spec.ts | 1091 --------------- tests/utils/constants.ts | 62 + 4 files changed, 1262 insertions(+), 2325 deletions(-) create mode 100644 tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegate.spec.ts delete mode 100644 tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP7Assets.spec.ts delete mode 100644 tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP8Assets.spec.ts diff --git a/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegate.spec.ts b/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegate.spec.ts new file mode 100644 index 000000000..e1b428f14 --- /dev/null +++ b/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegate.spec.ts @@ -0,0 +1,1200 @@ +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { ethers } from "hardhat"; +import { + UniversalProfile, + UniversalProfile__factory, + LSP6KeyManager, + LSP7Tester, + LSP7Tester__factory, + LSP8Tester, + LSP8Tester__factory, + URDRevert, + URDRevert__factory, + LSP6KeyManager__factory, + LSP1UniversalReceiverDelegate, + LSP1UniversalReceiverDelegate__factory +} from "../../types"; + +import { + ALL_PERMISSIONS_SET, + ADDRESS, + PERMISSIONS, + OPERATIONS, + allowedAddresses, +} from "../utils/keymanager"; + +import { + LSP5_ASSET_MAP_HASH, + LSP5_ARRAY_KEY, + RAW_INTERFACE_ID, + UNIVERSALRECEIVER_KEY, + INTERFACE_IDS, + ADDRESSPERMISSIONS_KEY, + ITEMS_ARRAY_KEY, + ARRAY_LENGTH, + INDEX, + TOKEN_ID +} from "../utils/constants"; + +describe("UniversalReceiverDelegate contract", () => { + let accounts: SignerWithAddress[]; + let owner1, owner2; + let keyManager1: LSP6KeyManager, keyManager2: LSP6KeyManager; + let universalReceiverDelegate: LSP1UniversalReceiverDelegate; + let universalProfile1: UniversalProfile, universalProfile2: UniversalProfile; + let URDRevert: URDRevert; + + beforeAll(async () => { + accounts = await ethers.getSigners(); + owner1 = accounts[0]; + owner2 = accounts[1]; + universalProfile1 = await new UniversalProfile__factory(owner1).deploy(owner1.address); + universalProfile2 = await new UniversalProfile__factory(owner2).deploy(owner2.address); + keyManager1 = await new LSP6KeyManager__factory(owner1).deploy(universalProfile1.address); + keyManager2 = await new LSP6KeyManager__factory(owner2).deploy(universalProfile2.address); + universalReceiverDelegate = await new LSP1UniversalReceiverDelegate__factory(owner1).deploy(); + URDRevert = await new URDRevert__factory(owner1).deploy(); + + + // Setting Permissions for UP1 + + // owner1 permissions + + await universalProfile1 + .connect(owner1) + .setData([ADDRESS.PERMISSIONS + owner1.address.substr(2)], [ALL_PERMISSIONS_SET]); + + // set the URD Key + await universalProfile1 + .connect(owner1) + .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate.address]); + + // set URD permissions + let URDPermissions = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); + await universalProfile1 + .connect(owner1) + .setData( + [ADDRESS.PERMISSIONS + universalReceiverDelegate.address.substr(2)], + [URDPermissions] + ); + + // switch account management to keyManager1 + await universalProfile1.connect(owner1).transferOwnership(keyManager1.address); + + // Setting Permissions for UP1 + + // owner2 permission + + await universalProfile2 + .connect(owner2) + .setData([ADDRESS.PERMISSIONS + owner2.address.substr(2)], [ALL_PERMISSIONS_SET]); + + // set the URD Key + await universalProfile2 + .connect(owner2) + .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate.address]); + + // set URD permissions + let URDPermissions2 = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); + await universalProfile2 + .connect(owner2) + .setData( + [ADDRESS.PERMISSIONS + universalReceiverDelegate.address.substr(2)], + [URDPermissions2] + ); + + // switch account management to keyManager2 + await universalProfile2.connect(owner2).transferOwnership(keyManager2.address); + + // fund UP with ether + await owner1.sendTransaction({ + to: universalProfile1.address, + value: ethers.utils.parseEther("10"), + }); + + await owner2.sendTransaction({ + to: universalProfile2.address, + value: ethers.utils.parseEther("10"), + }); + }) + + describe("Testing Deployement", () => { + + it("Deploys correctly, and compare owners", async () => { + const idOwner = await universalProfile1.callStatic.owner(); + expect(idOwner).toEqual(keyManager1.address); + const idOwnerSecond = await universalProfile2.callStatic.owner(); + expect(idOwnerSecond).toEqual(keyManager2.address); + }); + + it("Should be able to read UR key", async () => { + // UP1 + const [gettedAddress] = await universalProfile1 + .connect(owner1) + .getData([UNIVERSALRECEIVER_KEY]); + expect(await ethers.utils.getAddress(gettedAddress)).toEqual( + universalReceiverDelegate.address + ); + // UP2 + const [gettedAddressSecond] = await universalProfile2 + .connect(owner2) + .getData([UNIVERSALRECEIVER_KEY]); + expect(await ethers.utils.getAddress(gettedAddressSecond)).toEqual( + universalReceiverDelegate.address + ); + }); + + it("ensures owner is still universalProfile1's admin (=all permissions)", async () => { + let [permissions] = await universalProfile1.getData([ + ADDRESS.PERMISSIONS + owner1.address.substr(2), + ]); + expect(permissions).toEqual( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "Owner should have all permissions set" + ); + + // UP2 + let [permissionsSecond] = await universalProfile2.getData([ + ADDRESS.PERMISSIONS + owner2.address.substr(2), + ]); + expect(permissionsSecond).toEqual( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "Owner should have all permissions set" + ); + }); + + it("get URD permissions", async () => { + let [permissions] = await universalProfile1.getData([ + ADDRESS.PERMISSIONS + universalReceiverDelegate.address.substr(2), + ]); + expect(permissions).toEqual( + "0x0000000000000000000000000000000000000000000000000000000000000018", + "URD should have permissions" + ); // to setData and call + + // UP2 + let [permissionsSecond] = await universalProfile2.getData([ + ADDRESS.PERMISSIONS + universalReceiverDelegate.address.substr(2), + ]); + expect(permissionsSecond).toEqual( + "0x0000000000000000000000000000000000000000000000000000000000000018", + "URD should have permissions" + ); // to setData and call + }); + + it("Owner should be allowed to change keys", async () => { + // change universalReceiverDelegate1's permissions + let key = ADDRESS.PERMISSIONS + universalReceiverDelegate.address.substr(2); + + let payload = universalProfile1.interface.encodeFunctionData("setData", [ + [key], + [PERMISSIONS.SETDATA], + ]); + + let result = await keyManager1.connect(owner1).callStatic.execute(payload); + expect(result).toBeTruthy(); + + await keyManager1.connect(owner1).execute(payload); + let fetchedResult = await universalProfile1.callStatic.getData([key]); + expect(Number(fetchedResult)).toEqual(PERMISSIONS.SETDATA); + + // reset universalReceiverDelegate1 permissions + await keyManager1.execute( + universalProfile1.interface.encodeFunctionData("setData", [ + [key], + [ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32)], + ]) + ); + }); + }) + + describe("LSP7-DigitalAsset", () => { + + let LSP7tokenA, LSP7tokenB, LSP7tokenC, LSP7tokenD, LSP7tokenE; + beforeAll(async () => { + LSP7tokenA = await new LSP7Tester__factory(owner1).deploy("TokenA", "TKA", owner1.address); + LSP7tokenB = await new LSP7Tester__factory(owner1).deploy("TokenB", "TKB", owner1.address); + LSP7tokenC = await new LSP7Tester__factory(owner1).deploy("TokenC", "TKC", owner1.address); + LSP7tokenD = await new LSP7Tester__factory(owner1).deploy("TokenD", "TKD", owner1.address); + LSP7tokenE = await new LSP7Tester__factory(owner1).deploy("TokenE", "TKE", owner1.address); + }) + describe("Minting and Burning Behavior", () => { + it("Should mint tokenA and Register the Map and the Key in the Array", async () => { + // Token const + const tokenAMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenA.address.substr(2); + + let abi = LSP7tokenA.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenA.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Checking the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenAMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP7tokenA.address); + }) + + it("Should mint TokenB and Register the Map and the Key in the Array and Update the length", async () => { + // Token const + const tokenBMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenB.address.substr(2); + + let abi = LSP7tokenB.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenB.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenBMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP7); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP7tokenB.address); + }) + + it("Should send more token A and B and don't add or change something", async () => { + // Token const + const tokenAMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenA.address.substr(2); + const tokenBMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenB.address.substr(2); + + let abi = LSP7tokenB.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenB.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let abi1 = LSP7tokenA.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor1 = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenA.address, + 0, + abi1, + ]); + await keyManager1.execute(abiExecutor1, { from: owner1.address }); + + + let [indexAndInterfaceId1] = await universalProfile1.connect(owner1).getData([tokenAMapAsset]); + let [indexAndInterfaceId2] = await universalProfile1.connect(owner1).getData([tokenBMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [item3Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM3]); + + expect(indexAndInterfaceId1).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(indexAndInterfaceId2).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP7); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP7tokenA.address); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP7tokenB.address); + expect(item3Address).toEqual("0x"); + }) + + it("Should mint token C and Register the Map and the key in the Array and update the length", async () => { + // Token const + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenC.address.substr(2); + + let abi = LSP7tokenC.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenC.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item3Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM3]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.TWO + RAW_INTERFACE_ID.LSP7); + expect(arrayLength).toEqual(ARRAY_LENGTH.THREE); + expect(await ethers.utils.getAddress(item3Address)).toEqual(LSP7tokenC.address); + }) + + + + it("Should Burn token B and update the key in the Array and remove the map", async () => { + // Token const + const tokenBMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenB.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenC.address.substr(2); + + let abi = LSP7tokenB.interface.encodeFunctionData("burn", [ + universalProfile1.address, + "20", + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenB.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdForB] = await universalProfile1.connect(owner1).getData([tokenBMapAsset]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + // Now the Map of Token C takes the index of the removed Token B and item2 will be token C instead of B + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP7); + expect(indexAndInterfaceIdForB).toEqual("0x"); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP7tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + }); + + it("Should mint Token D and registering the Map and the key in the Array", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenD.address.substr(2); + + let abi = LSP7tokenD.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item3Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM3]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.TWO + RAW_INTERFACE_ID.LSP7); + expect(arrayLength).toEqual(ARRAY_LENGTH.THREE); + expect(await ethers.utils.getAddress(item3Address)).toEqual(LSP7tokenD.address); + }) + + it("Should burn Token D and remove the Map and the key in the Array and update the length", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenD.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenC.address.substr(2); + + let abi = LSP7tokenD.interface.encodeFunctionData("burn", [ + universalProfile1.address, + "10", + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdForD] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + /* Now the none of the existing map doesn't change the index since + the token removed is placed last in the array */ + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP7); + expect(indexAndInterfaceIdForD).toEqual("0x"); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP7tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + }) + + it("Should burn token A and update the key in the array and remove Map and update array length", async () => { + // Token const + const tokenAMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenA.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenC.address.substr(2); + + let abi = LSP7tokenA.interface.encodeFunctionData("burn", [ + universalProfile1.address, + "20", + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenA.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + let [indexAndInterfaceIdForA] = await universalProfile1.connect(owner1).getData([tokenAMapAsset]); + + expect(indexAndInterfaceIdForA).toEqual("0x"); + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP7tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + }) + + it("Should burn token C and update the key in the array and remove Map and update array length", async () => { + // Token const + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenC.address.substr(2); + + let abi = LSP7tokenC.interface.encodeFunctionData("burn", [ + universalProfile1.address, + "10", + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenC.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + expect(indexAndInterfaceId).toEqual("0x"); + expect(item1Address).toEqual("0x"); + expect(arrayLength).toEqual(ARRAY_LENGTH.ZERO); + }) + it("Should mint token E and register the Map and the key in the Array", async () => { + // Token const + const tokenEMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenE.address.substr(2); + + let abi = LSP7tokenE.interface.encodeFunctionData("mint", [ + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenE.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenEMapAsset]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP7tokenE.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + }) + }) + + describe("Transferring tokens between 2 UP", () => { + it("Should transfer 5 tokensE to UP2 and keep 5 tokensE in UP1 and register the entries in UP2 and keep them also in UP1", async () => { + // Token const + const tokenEMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenE.address.substr(2); + + let abi = LSP7tokenE.interface.encodeFunctionData("transfer", [ + universalProfile1.address, + universalProfile2.address, + "5", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenE.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP1] = await universalProfile1.connect(owner1).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP1).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1AddressUP1)).toEqual(LSP7tokenE.address); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ONE); + + // Check the Registred entries in UP2 + + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP7tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }); + + it("Should transfer 5 tokensE to UP2 from UP1 and Keep 0 token E in UP1 then clear all entries", async () => { + // Token const + const tokenEMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenE.address.substr(2); + + let abi = LSP7tokenE.interface.encodeFunctionData("transfer", [ + universalProfile1.address, + universalProfile2.address, + "5", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenE.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP1] = await universalProfile1.connect(owner1).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP1).toEqual("0x"); + expect(item1AddressUP1).toEqual("0x"); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ZERO); + + // Check the Registred entries in UP2 + + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP7tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + + }); + + it("Should mint token D to UP2 and register the map and the key in the array", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenD.address.substr(2); + + let abi = LSP7tokenD.interface.encodeFunctionData("mint", [ + universalProfile2.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await keyManager2.connect(owner2).execute(abiExecutor); + + // Check the Registred entries in UP2 + + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item2AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item2AddressUP2)).toEqual(LSP7tokenD.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.TWO); + }); + + it("Should Transfer token D from UP2 to UP1 and remove all Token D entries", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP7tokenD.address.substr(2); + + let abi = LSP7tokenD.interface.encodeFunctionData("transfer", [ + universalProfile2.address, + universalProfile1.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await keyManager2.connect(owner2).execute(abiExecutor); + + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP1] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP1).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP7); + expect(await ethers.utils.getAddress(item1AddressUP1)).toEqual(LSP7tokenD.address); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ONE); + + // Check the Registred entries in UP2 + // since token D is removed, the first item will be now the token E + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x"); + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP7tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }); + }) + + describe("Implementing URDRevert", () => { + beforeAll(async () => { + let abiSetData = universalProfile2.interface.encodeFunctionData("setData", [ + [UNIVERSALRECEIVER_KEY], + [URDRevert.address], + ]); + await keyManager2.connect(owner2).execute(abiSetData, { from: owner2.address }); + }) + + it("Should revert when sending tokens from UP1 to UP2 that implement URDRevert", async () => { + let abi = LSP7tokenD.interface.encodeFunctionData("transfer", [ + universalProfile1.address, + universalProfile2.address, + "10", + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await expect(keyManager1.execute(abiExecutor)).toBeRevertedWith("This Contract reverts"); + }); + + it("Should not register any token in UP2 nor remove any in UP1", async () => { + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(await ethers.utils.getAddress(item1AddressUP1)).toEqual(LSP7tokenD.address); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ONE); + + // Check the Registred entries in UP2 + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP7tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }) + + it("Resetting normal UniversalReceiverDelegate", async () => { + let abiSetData = universalProfile2.interface.encodeFunctionData("setData", [ + [UNIVERSALRECEIVER_KEY], + [universalReceiverDelegate.address], + ]); + await keyManager2.connect(owner2).execute(abiSetData, { from: owner2.address }); + }) + it("Burning all token in UP1 and UP2 and clear the entries", async () => { + // burning token D in UP1 + let abi = LSP7tokenD.interface.encodeFunctionData("burn", [ + universalProfile1.address, + "10", + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenD.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // burning token E in UP2 + let abi1 = LSP7tokenE.interface.encodeFunctionData("burn", [ + universalProfile2.address, + "10", + "0x", + ]); + let abiExecutor1 = universalProfile2.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP7tokenE.address, + 0, + abi1, + ]); + await keyManager2.execute(abiExecutor1, { from: owner2.address }); + }) + + }) + + + }); + + describe("LSP8-IdentifiableDigitalAsset", () => { + + let LSP8tokenA, LSP8tokenB, LSP8tokenC, LSP8tokenD, LSP8tokenE; + beforeAll(async () => { + LSP8tokenA = await new LSP8Tester__factory(owner1).deploy("TokenA", "TKA", owner1.address); + LSP8tokenB = await new LSP8Tester__factory(owner1).deploy("TokenB", "TKB", owner1.address); + LSP8tokenC = await new LSP8Tester__factory(owner1).deploy("TokenC", "TKC", owner1.address); + LSP8tokenD = await new LSP8Tester__factory(owner1).deploy("TokenD", "TKD", owner1.address); + LSP8tokenE = await new LSP8Tester__factory(owner1).deploy("TokenE", "TKE", owner1.address); + }) + describe("Minting and Burning Behavior", () => { + it("Should mint tokenA and Register the Map and the Key in the Array", async () => { + // Token const + const tokenAMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenA.address.substr(2); + + let abi = LSP8tokenA.interface.encodeFunctionData("mint", [ + universalProfile1.address, + TOKEN_ID.ONE, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenA.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Checking the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenAMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP8); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP8tokenA.address); + }) + + it("Should mint TokenB and Register the Map and the Key in the Array and Update the length", async () => { + // Token const + const tokenBMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenB.address.substr(2); + + let abi = LSP8tokenB.interface.encodeFunctionData("mint", [ + universalProfile1.address, + TOKEN_ID.TWO, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenB.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenBMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP8); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP8tokenB.address); + }) + + it("Should mint token C and Register the Map and the key in the Array and update the length", async () => { + // Token const + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenC.address.substr(2); + + let abi = LSP8tokenC.interface.encodeFunctionData("mint", [ + universalProfile1.address, + TOKEN_ID.THREE, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenC.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item3Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM3]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.TWO + RAW_INTERFACE_ID.LSP8); + expect(arrayLength).toEqual(ARRAY_LENGTH.THREE); + expect(await ethers.utils.getAddress(item3Address)).toEqual(LSP8tokenC.address); + }) + + + + it("Should Burn token B and update the key in the Array and remove the map", async () => { + // Token const + const tokenBMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenB.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenC.address.substr(2); + + let abi = LSP8tokenB.interface.encodeFunctionData("burn", [ + TOKEN_ID.TWO, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenB.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdForB] = await universalProfile1.connect(owner1).getData([tokenBMapAsset]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + // Now the Map of Token C takes the index of the removed Token B and item2 will be token C instead of B + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP8); + expect(indexAndInterfaceIdForB).toEqual("0x"); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP8tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + }); + + it("Should mint Token D and registering the Map and the key in the Array", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenD.address.substr(2); + + let abi = LSP8tokenD.interface.encodeFunctionData("mint", [ + universalProfile1.address, + TOKEN_ID.FOUR, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenD.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item3Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM3]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.TWO + RAW_INTERFACE_ID.LSP8); + expect(arrayLength).toEqual(ARRAY_LENGTH.THREE); + expect(await ethers.utils.getAddress(item3Address)).toEqual(LSP8tokenD.address); + }) + + it("Should burn Token D and remove the Map and the key in the Array and update the length", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenD.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenC.address.substr(2); + + let abi = LSP8tokenD.interface.encodeFunctionData("burn", [ + TOKEN_ID.FOUR, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenD.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item2Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdForD] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + /* Now the none of the existing map doesn't change the index since + the token removed is placed last in the array */ + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP8); + expect(indexAndInterfaceIdForD).toEqual("0x"); + expect(await ethers.utils.getAddress(item2Address)).toEqual(LSP8tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.TWO); + }) + + it("Should burn token A and update the key in the array and remove Map and update array length", async () => { + // Token const + const tokenAMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenA.address.substr(2); + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenC.address.substr(2); + + let abi = LSP8tokenA.interface.encodeFunctionData("burn", [ + TOKEN_ID.ONE, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenA.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdForC] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + let [indexAndInterfaceIdForA] = await universalProfile1.connect(owner1).getData([tokenAMapAsset]); + + expect(indexAndInterfaceIdForA).toEqual("0x"); + expect(indexAndInterfaceIdForC).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP8); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP8tokenC.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + }) + + it("Should burn token C and update the key in the array and remove Map and update array length", async () => { + // Token const + const tokenCMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenC.address.substr(2); + + let abi = LSP8tokenC.interface.encodeFunctionData("burn", [ + TOKEN_ID.THREE, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenC.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenCMapAsset]); + + expect(indexAndInterfaceId).toEqual("0x"); + expect(item1Address).toEqual("0x"); + expect(arrayLength).toEqual(ARRAY_LENGTH.ZERO); + }) + it("Should mint token E and register the Map and the key in the Array", async () => { + // Token const + const tokenEMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenE.address.substr(2); + + let abi = LSP8tokenE.interface.encodeFunctionData("mint", [ + universalProfile1.address, + TOKEN_ID.FIVE, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenE.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries + + let [arrayLength] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1Address] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceId] = await universalProfile1.connect(owner1).getData([tokenEMapAsset]); + + expect(indexAndInterfaceId).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP8); + expect(await ethers.utils.getAddress(item1Address)).toEqual(LSP8tokenE.address); + expect(arrayLength).toEqual(ARRAY_LENGTH.ONE); + }) + }) + + describe("Transferring tokens between 2 UP", () => { + it("Should transfer token E to UP2 and register the entries in UP2 ", async () => { + // Token const + const tokenEMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenE.address.substr(2); + + let abi = LSP8tokenE.interface.encodeFunctionData("transfer", [ + universalProfile1.address, + universalProfile2.address, + TOKEN_ID.FIVE, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenE.address, + 0, + abi, + ]); + await keyManager1.execute(abiExecutor, { from: owner1.address }); + + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP1] = await universalProfile1.connect(owner1).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP1).toEqual("0x"); + expect(item1AddressUP1).toEqual("0x"); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ZERO); + + // Check the Registred entries in UP2 + + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP8); + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP8tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }); + + it("Should mint token D to UP2 and register the map and the key in the array", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenD.address.substr(2); + + let abi = LSP8tokenD.interface.encodeFunctionData("mint", [ + universalProfile2.address, + TOKEN_ID.FOUR, + false, + "0x", + ]); + let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenD.address, + 0, + abi, + ]); + await keyManager2.connect(owner2).execute(abiExecutor); + + // Check the Registred entries in UP2 + + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item2AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM2]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x" + INDEX.ONE + RAW_INTERFACE_ID.LSP8); + expect(await ethers.utils.getAddress(item2AddressUP2)).toEqual(LSP8tokenD.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.TWO); + }); + + it("Should Transfer token D from UP2 to UP1 and remove all Token D entries", async () => { + // Token const + const tokenDMapAsset = LSP5_ASSET_MAP_HASH + LSP8tokenD.address.substr(2); + + let abi = LSP8tokenD.interface.encodeFunctionData("transfer", [ + universalProfile2.address, + universalProfile1.address, + TOKEN_ID.FOUR, + false, + "0x", + ]); + let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenD.address, + 0, + abi, + ]); + await keyManager2.connect(owner2).execute(abiExecutor); + + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP1] = await universalProfile1.connect(owner1).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP1).toEqual("0x" + INDEX.ZERO + RAW_INTERFACE_ID.LSP8); + expect(await ethers.utils.getAddress(item1AddressUP1)).toEqual(LSP8tokenD.address); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ONE); + + // Check the Registred entries in UP2 + // since token D is removed, the first item will be now the token E + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + let [indexAndInterfaceIdUP2] = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); + + expect(indexAndInterfaceIdUP2).toEqual("0x"); + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP8tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }); + }) + + describe("Implementing URDRevert", () => { + beforeAll(async () => { + let abiSetData = universalProfile2.interface.encodeFunctionData("setData", [ + [UNIVERSALRECEIVER_KEY], + [URDRevert.address], + ]); + await keyManager2.connect(owner2).execute(abiSetData, { from: owner2.address }); + }) + + it("Should revert when sending tokens from UP1 to UP2 that implement URDRevert", async () => { + let abi = LSP8tokenD.interface.encodeFunctionData("transfer", [ + universalProfile1.address, + universalProfile2.address, + TOKEN_ID.FOUR, + false, + "0x", + ]); + let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ + OPERATIONS.CALL, + LSP8tokenD.address, + 0, + abi, + ]); + await expect(keyManager1.execute(abiExecutor)).toBeRevertedWith("This Contract reverts"); + }); + + it("Should not register any token in UP2 nor remove any in UP1", async () => { + // Check the Registred entries in UP1 + + let [arrayLengthUP1] = await universalProfile1.connect(owner1).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP1] = await universalProfile1.connect(owner1).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(await ethers.utils.getAddress(item1AddressUP1)).toEqual(LSP8tokenD.address); + expect(arrayLengthUP1).toEqual(ARRAY_LENGTH.ONE); + + // Check the Registred entries in UP2 + let [arrayLengthUP2] = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_KEY]); + let [item1AddressUP2] = await universalProfile2.connect(owner2).getData([ITEMS_ARRAY_KEY.ITEM1]); + + expect(await ethers.utils.getAddress(item1AddressUP2)).toEqual(LSP8tokenE.address); + expect(arrayLengthUP2).toEqual(ARRAY_LENGTH.ONE); + }) + + }) + + + }); + +}); \ No newline at end of file diff --git a/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP7Assets.spec.ts b/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP7Assets.spec.ts deleted file mode 100644 index 1ba0d201c..000000000 --- a/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP7Assets.spec.ts +++ /dev/null @@ -1,1234 +0,0 @@ -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { ethers } from "hardhat"; -import { - LSP6KeyManager__factory, - LSP1UniversalReceiverDelegate, - LSP1UniversalReceiverDelegate__factory, -} from "../../types"; -import { - UniversalProfile, - UniversalProfile__factory, - KeyManagerHelper, - LSP6KeyManager, - LSP7Tester, - LSP7Tester__factory, - URDRevert, - URDRevert__factory, -} from "../../types"; - -import { - ALL_PERMISSIONS_SET, - ADDRESS, - PERMISSIONS, - OPERATIONS, - allowedAddresses, -} from "../utils/keymanager"; -import { INTERFACE_IDS, ADDRESSPERMISSIONS_KEY } from "../utils/constants"; - -// Get key: keccak256('LSP1UniversalReceiverDelegate') -const UNIVERSALRECEIVER_KEY = "0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47"; -const LSP5_ASSET_MAP_HASH = "0x812c4334633eb81600000000"; -const LSP5_ARRAY_HASH = "0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b"; // keccak256("LSPASSETS[]") -const INTERFACE_ID = "e33f65c3"; - -describe("Universal Receiver Delegate Contract", () => { - describe("Deployement Testing", () => { - let accounts: SignerWithAddress[]; - let abiCoder; - let owner; - let owner2; - let keyManager1: LSP6KeyManager; - let keyManager2: LSP6KeyManager; - let universalReceiverDelegate1: LSP1UniversalReceiverDelegate; - let universalReceiverDelegate2: LSP1UniversalReceiverDelegate; - let universalProfile1: UniversalProfile; - let universalProfile2: UniversalProfile; - let tokenA: LSP7Tester; - let tokenB: LSP7Tester; - let tokenC: LSP7Tester; - let tokenD: LSP7Tester; - let tokenE: LSP7Tester; - let URDrevert: URDRevert; - - beforeAll(async () => { - accounts = await ethers.getSigners(); - abiCoder = await ethers.utils.defaultAbiCoder; - owner = accounts[0]; - owner2 = accounts[1]; - universalProfile1 = await new UniversalProfile__factory(owner).deploy(owner.address); - universalProfile2 = await new UniversalProfile__factory(owner2).deploy(owner2.address); - tokenA = await new LSP7Tester__factory(owner).deploy("TokenA", "TKA", owner.address); - tokenB = await new LSP7Tester__factory(owner).deploy("TokenB", "TKB", owner.address); - tokenC = await new LSP7Tester__factory(owner).deploy("TokenC", "TKC", owner.address); - tokenD = await new LSP7Tester__factory(owner).deploy("TokenD", "TKD", owner.address); - tokenE = await new LSP7Tester__factory(owner).deploy("TokenE", "TKE", owner.address); - universalReceiverDelegate1 = await new LSP1UniversalReceiverDelegate__factory(owner).deploy(); - universalReceiverDelegate2 = await new LSP1UniversalReceiverDelegate__factory(owner2).deploy(); - URDrevert = await new URDRevert__factory(owner).deploy(); - keyManager1 = await new LSP6KeyManager__factory(owner).deploy(universalProfile1.address); - keyManager2 = await new LSP6KeyManager__factory(owner2).deploy(universalProfile2.address); - - // FOR UNIVERSALPROFILE 1 - - // owner permission - - await universalProfile1 - .connect(owner) - .setData([ADDRESS.PERMISSIONS + owner.address.substr(2)], [ALL_PERMISSIONS_SET]); - - // set the URD Key - await universalProfile1 - .connect(owner) - .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate1.address]); - - // set URD permissions - let URDPermissions = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); - await universalProfile1 - .connect(owner) - .setData( - [ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2)], - [URDPermissions] - ); - - // set URDRevert permissions - - let URDRevertPermissions = ethers.utils.hexZeroPad( - PERMISSIONS.SETDATA + PERMISSIONS.CALL, - 32 - ); - await universalProfile1 - .connect(owner) - .setData([ADDRESS.PERMISSIONS + URDrevert.address.substr(2)], [URDRevertPermissions]); - - // switch account management to keyManager1 - await universalProfile1.connect(owner).transferOwnership(keyManager1.address); - - // fund UP with ether - await owner.sendTransaction({ - to: universalProfile1.address, - value: ethers.utils.parseEther("10"), - }); - - // FOR UNIVERSALPROFILE 2 - - // owner2 permission - - await universalProfile2 - .connect(owner2) - .setData([ADDRESS.PERMISSIONS + owner2.address.substr(2)], [ALL_PERMISSIONS_SET]); - - // set the URD Key - await universalProfile2 - .connect(owner2) - .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate2.address]); - - // set URD permissions - let URDPermissions2 = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); - await universalProfile2 - .connect(owner2) - .setData( - [ADDRESS.PERMISSIONS + universalReceiverDelegate2.address.substr(2)], - [URDPermissions2] - ); - - // set URDRevert permissions - - let URDRevertPermissions2 = ethers.utils.hexZeroPad( - PERMISSIONS.SETDATA + PERMISSIONS.CALL, - 32 - ); - await universalProfile2 - .connect(owner2) - .setData([ADDRESS.PERMISSIONS + URDrevert.address.substr(2)], [URDRevertPermissions2]); - - // switch account management to keyManager2 - await universalProfile2.connect(owner2).transferOwnership(keyManager2.address); - - // fund UP with ether - await owner2.sendTransaction({ - to: universalProfile2.address, - value: ethers.utils.parseEther("10"), - }); - }); - - beforeEach(async () => { - universalProfile1.connect(owner.address); - keyManager1.connect(owner.address); - universalProfile2.connect(owner2.address); - keyManager2.connect(owner2.address); - }); - - it("Should read ISLP1 Delegate interface id", async () => { - const interfaceID = "0xc2d7bcc1"; - const result = await universalReceiverDelegate1.callStatic.supportsInterface(interfaceID); - const resultSecond = await universalReceiverDelegate2.callStatic.supportsInterface( - interfaceID - ); - - expect(result).toBeTruthy(); - expect(resultSecond).toBeTruthy(); - }); - - it("Deploys correctly, and compare owners", async () => { - const idOwner = await universalProfile1.callStatic.owner(); - expect(idOwner).toEqual(keyManager1.address); - const idOwnerSecond = await universalProfile2.callStatic.owner(); - expect(idOwnerSecond).toEqual(keyManager2.address); - }); - - it("Should be able to read UR key", async () => { - // UP1 - const [gettedAddress] = await universalProfile1 - .connect(owner) - .getData([UNIVERSALRECEIVER_KEY]); - expect(await ethers.utils.getAddress(gettedAddress)).toEqual( - universalReceiverDelegate1.address - ); - // UP2 - const [gettedAddressSecond] = await universalProfile2 - .connect(owner2) - .getData([UNIVERSALRECEIVER_KEY]); - expect(await ethers.utils.getAddress(gettedAddressSecond)).toEqual( - universalReceiverDelegate2.address - ); - }); - - it("ensures owner is still universalProfile1's admin (=all permissions)", async () => { - let [permissions] = await universalProfile1.getData([ - ADDRESS.PERMISSIONS + owner.address.substr(2), - ]); - expect(permissions).toEqual( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "Owner should have all permissions set" - ); - - // UP2 - let [permissionsSecond] = await universalProfile2.getData([ - ADDRESS.PERMISSIONS + owner2.address.substr(2), - ]); - expect(permissionsSecond).toEqual( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "Owner should have all permissions set" - ); - }); - - it("get URD permissions", async () => { - let [permissions] = await universalProfile1.getData([ - ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2), - ]); - expect(permissions).toEqual( - "0x0000000000000000000000000000000000000000000000000000000000000018", - "URD should have permissions" - ); // to setData and call - - // UP2 - let [permissionsSecond] = await universalProfile2.getData([ - ADDRESS.PERMISSIONS + universalReceiverDelegate2.address.substr(2), - ]); - expect(permissionsSecond).toEqual( - "0x0000000000000000000000000000000000000000000000000000000000000018", - "URD should have permissions" - ); // to setData and call - }); - - it("Owner should be allowed to change keys", async () => { - // change universalReceiverDelegate1's permissions - let key = ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2); - - let payload = universalProfile1.interface.encodeFunctionData("setData", [ - [key], - [PERMISSIONS.SETDATA], - ]); - - let result = await keyManager1.connect(owner).callStatic.execute(payload); - expect(result).toBeTruthy(); - - await keyManager1.connect(owner).execute(payload); - let fetchedResult = await universalProfile1.callStatic.getData([key]); - expect(Number(fetchedResult)).toEqual(PERMISSIONS.SETDATA); - - // reset universalReceiverDelegate1 permissions - await keyManager1.execute( - universalProfile1.interface.encodeFunctionData("setData", [ - [key], - [ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32)], - ]) - ); - }); - describe("Recepient Hook", () => { - beforeAll(async () => { - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x34", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - it("=> Should Register the Asset Map for Token A with index 0 and interface Id", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("=> Should Register the Length of The Array : `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // length of the array is 1 - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token A in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenA.address); - }); - - it("=> Should Have the Second Key in the Array empty for now", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Transfer Token B", async () => { - let abi = tokenB.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x32", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenB.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Register the Asset Map for Token B with index 1 and interface Id", async () => { - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Should Register the Address of Token B in the Second Key in the Array", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenB.address); - }); - - it("=> Safety Check for all Registred tokens", async () => { - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token B - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + B) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenB.address); - }); - - it("=> Should Call Recepient Hook in Token A and B and don't change anything", async () => { - // Calling the Hook Again in Both Tokens - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x34", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - - abi = tokenB.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x32", - ]); - abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenB.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token B - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + B) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenB.address); - }); - - it("=> Should Have the Third Key in the Array empty for now", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Transfer Token C", async () => { - let abi = tokenC.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x34", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenC.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Register the Asset Map for Token C with index 2 and interface Id", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000002" + INTERFACE_ID); - }); - - it("=> Should Update the Length of The Array to `3`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000003" - ); - }); - - it("=> Should Register the Address of Token C in the Third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - }); - - describe("Sender Hook", () => { - it("=> Eliminating Token B", async () => { - let abi = tokenB.interface.encodeFunctionData("burn", [ - universalProfile1.address, - "20", - "0x43", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenB.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Item 2 in the LSP5ASSET Array Should be the address of Token C", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - - it("=> Item 3 Should not exist", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Asset Map for Token B should not exist anymore", async () => { - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Asset Map for Token C refer to index 1 now", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - }); - - describe("Testing adding and eliminating behavior", () => { - it("Receive new token D", async () => { - let abi = tokenD.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x43", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `3`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000003" - ); - }); - - it("=> Should Register the Address of Token D in the third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenD.address); - }); - - it("=> Asset Map for Token D refer to index 2 now", async () => { - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000002" + INTERFACE_ID); - }); - - it("=> Eliminating Token D", async () => { - let abi = tokenD.interface.encodeFunctionData("burn", [ - universalProfile1.address, - "10", - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Asset Map for Token D should be empty now", async () => { - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token D from the third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Next slot should be empty", async () => { - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item4_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Safety Check for Token A and C", async () => { - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token C - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + C) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenC.address); - }); - - it("=> Sending More Token A", async () => { - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Next slot should be empty", async () => { - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item4_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Sending Existing Token shouldnt change anyhting", async () => { - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token C - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + C) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenC.address); - }); - - it("=> Eliminating Token A", async () => { - let abi = tokenA.interface.encodeFunctionData("burn", [ - universalProfile1.address, - "30", - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Asset Map for Token A should be empty now", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token A from the first Key in the Array and replace it with token C", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - - it("=> Next slot should be empty", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Eliminating Token C", async () => { - let abi = tokenC.interface.encodeFunctionData("burn", [ - universalProfile1.address, - "10", - "0x11", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenC.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `0`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000000" - ); - }); - - it("=> Asset Map for Token C should be empty now", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token C from the first Key ", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Next slot should be empty", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Keys Should be Empty", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - const item5_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000004"; - const Items = [ - item1_Array_Key, - item2_Array_Key, - item3_Array_Key, - item4_Array_Key, - item5_Array_Key, - ]; - let gettedResult = await universalProfile1.connect(owner).getData(Items); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x", "0x"]); - }); - - it("=> Token AssetMap Should be Empty", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - const AssetMap = [tokenAMapAsset, tokenBMapAsset, tokenCMapAsset, tokenDMapAsset]; - let gettedResult = await universalProfile1.connect(owner).getData(AssetMap); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x"]); - }); - - it("Receive token A again ", async () => { - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token A in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenA.address); - }); - - it("=> Asset Map for Token A refer to index 0 ", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Eliminate token A again ", async () => { - let abi = tokenA.interface.encodeFunctionData("burn", [ - universalProfile1.address, - "10", - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("Receive token E ", async () => { - let abi = tokenE.interface.encodeFunctionData("mint", [ - universalProfile1.address, - "10", - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenE.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token E in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenE.address); - }); - - it("=> Asset Map for Token E refer to index 0 ", async () => { - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("=> Keys Should be Empty bur first Key should exist", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - const item5_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000004"; - const Items = [item2_Array_Key, item3_Array_Key, item4_Array_Key, item5_Array_Key]; - let gettedResult = await universalProfile1.connect(owner).getData(Items); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x"]); - - let [gettedAsset] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedAsset)).toEqual(tokenE.address); - }); - - it("=> Token AssetMap Should be Empty but for E should exist", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - const AssetMap = [tokenAMapAsset, tokenBMapAsset, tokenCMapAsset, tokenDMapAsset]; - let gettedMaps = await universalProfile1.connect(owner).getData(AssetMap); - expect(gettedMaps).toEqual(["0x", "0x", "0x", "0x"]); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - - describe("Transfering tokens between 2 UP", () => { - it("Should transfer 5 tokensE to UP2 and keep 5 tokensE in UP1", async () => { - let abi = tokenE.interface.encodeFunctionData("transfer", [ - universalProfile1.address, - universalProfile2.address, - "5", - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenE.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("Should keep All keys in UP1 intact", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenE.address); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Check if keys are registred after sending tokens in UP2", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenE.address); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Should transfer 5 tokensE to UP2 from UP1 and Keep 0 tokensE", async () => { - let abi = tokenE.interface.encodeFunctionData("transfer", [ - universalProfile1.address, - universalProfile2.address, - "5", - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenE.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("Keys in UP2 Should be still registred", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenE.address); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Next slot should be intact in UP2 as we didnt send new tokens", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(gettedResult1).toEqual("0x"); - }); - - it("Should clear keys from UP1 as balance of tokensE is 0", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000000" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(gettedResult1).toEqual("0x"); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - expect(gettedResult2[0]).toEqual("0x"); - }); - - it("Mint tokensD to UP2", async () => { - let abi = tokenD.interface.encodeFunctionData("mint", [ - universalProfile2.address, - "10", - false, - "0x11", - ]); - let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager2.connect(owner2).execute(abiExecutor); - }); - - it("Check if keys are registred after sending tokensD in UP2", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - - it("Should Transfer tokenD from UP2 to UP1: clear tokenD from UP2 and register it in UP1", async () => { - let abi = tokenD.interface.encodeFunctionData("transfer", [ - universalProfile2.address, - universalProfile1.address, - "10", - false, - "0x11", - ]); - let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager2.connect(owner2).execute(abiExecutor); - }); - - it("Should remove tokenD keys after sending tokensD from UP2 to UP1", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(gettedResult1).toEqual("0x"); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x"); - }); - - it("Should regsiter tokenD keys after sending tokensD from UP2 to UP1", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - - describe("Implementing URD that reverts", () => { - beforeAll(async () => { - let abiSetData = universalProfile2.interface.encodeFunctionData("setData", [ - [UNIVERSALRECEIVER_KEY], - [URDrevert.address], - ]); - await keyManager2.connect(owner2).execute(abiSetData, { from: owner2.address }); - }); - - it("Should revert when sending tokens to UP2 (Transfer Function that have the hook after deducting amount)", async () => { - let abi = tokenD.interface.encodeFunctionData("transfer", [ - universalProfile1.address, - universalProfile2.address, - "10", - false, - "0x11", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await expect(keyManager1.execute(abiExecutor)).toBeRevertedWith("This Contract reverts"); - }); - - it("Should check that token didn't get send", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - }); -}); diff --git a/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP8Assets.spec.ts b/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP8Assets.spec.ts deleted file mode 100644 index 45956cb9d..000000000 --- a/tests/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateForLSP8Assets.spec.ts +++ /dev/null @@ -1,1091 +0,0 @@ -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; -import { ethers } from "hardhat"; -import { - LSP6KeyManager__factory, - LSP1UniversalReceiverDelegate, - LSP1UniversalReceiverDelegate__factory, -} from "../../types"; -import { - UniversalProfile, - UniversalProfile__factory, - KeyManagerHelper, - LSP6KeyManager, - LSP8Tester, - LSP8Tester__factory, - URDRevert, - URDRevert__factory, -} from "../../types"; - -import { - ALL_PERMISSIONS_SET, - ADDRESS, - PERMISSIONS, - OPERATIONS, - allowedAddresses, -} from "../utils/keymanager"; -import { INTERFACE_IDS, ADDRESSPERMISSIONS_KEY } from "../utils/constants"; - -// Get key: keccak256('LSP1UniversalReceiverDelegate') -const UNIVERSALRECEIVER_KEY = "0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47"; -const LSP5_ASSET_MAP_HASH = "0x812c4334633eb81600000000"; -const LSP5_ARRAY_HASH = "0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b"; // keccak256("LSPASSETS[]") -const INTERFACE_ID = "49399145"; -const TOKEN_ID1 = "0xad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5"; -const TOKEN_ID2 = "0xd4d1a59767271eefdc7830a772b9732a11d503531d972ab8c981a6b1c0e666e5"; -const TOKEN_ID3 = "0x3672b35640006da199633c5c75015da83589c4fb84ef8276b18076529e3d3196"; -const TOKEN_ID4 = "0x80a6c6138772c2d7c710a3d49f4eea603028994b7e390f670dd68566005417f0"; -const TOKEN_ID5 = "0x5c6f8b1aed769a328dad1ae15220e93730cdd52cb12817ae5fd8c15023d660d3"; -const TOKEN_ID6 = "0x65ce3c3668a850c4f9fce91762a3fb886380399f02a9eb1495055234e7c0287a"; -const TOKEN_ID7 = "0x00121ee2bd9802ce88a413ac1851c8afe6fe7474fb5d1b7da4475151b013da53"; -const TOKEN_ID8 = "0x367f9d97f8dd1bece61f8b74c5db7616958147682674fd32de73490bd6347f60"; - -describe("Universal Receiver Delegate Contract", () => { - describe("Deployement Testing", () => { - let accounts: SignerWithAddress[]; - let abiCoder; - let owner; - let owner2; - let keyManager1: LSP6KeyManager; - let keyManager2: LSP6KeyManager; - let universalReceiverDelegate1: LSP1UniversalReceiverDelegate; - let universalReceiverDelegate2: LSP1UniversalReceiverDelegate; - let universalProfile1: UniversalProfile; - let universalProfile2: UniversalProfile; - let tokenA: LSP8Tester; - let tokenB: LSP8Tester; - let tokenC: LSP8Tester; - let tokenD: LSP8Tester; - let tokenE: LSP8Tester; - let URDrevert: URDRevert; - - beforeAll(async () => { - accounts = await ethers.getSigners(); - abiCoder = await ethers.utils.defaultAbiCoder; - owner = accounts[0]; - owner2 = accounts[1]; - universalProfile1 = await new UniversalProfile__factory(owner).deploy(owner.address); - universalProfile2 = await new UniversalProfile__factory(owner2).deploy(owner2.address); - tokenA = await new LSP8Tester__factory(owner).deploy("TokenA", "TKA", owner.address); - tokenB = await new LSP8Tester__factory(owner).deploy("TokenB", "TKB", owner.address); - tokenC = await new LSP8Tester__factory(owner).deploy("TokenC", "TKC", owner.address); - tokenD = await new LSP8Tester__factory(owner).deploy("TokenD", "TKD", owner.address); - tokenE = await new LSP8Tester__factory(owner).deploy("TokenE", "TKE", owner.address); - universalReceiverDelegate1 = await new LSP1UniversalReceiverDelegate__factory(owner).deploy(); - universalReceiverDelegate2 = await new LSP1UniversalReceiverDelegate__factory(owner2).deploy(); - URDrevert = await new URDRevert__factory(owner).deploy(); - keyManager1 = await new LSP6KeyManager__factory(owner).deploy(universalProfile1.address); - keyManager2 = await new LSP6KeyManager__factory(owner2).deploy(universalProfile2.address); - - // FOR UNIVERSALPROFILE 1 - - // owner permission - - await universalProfile1 - .connect(owner) - .setData([ADDRESS.PERMISSIONS + owner.address.substr(2)], [ALL_PERMISSIONS_SET]); - - // set the URD Key - await universalProfile1 - .connect(owner) - .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate1.address]); - - // set URD permissions - let URDPermissions = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); - await universalProfile1 - .connect(owner) - .setData( - [ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2)], - [URDPermissions] - ); - - // set URDRevert permissions - - let URDRevertPermissions = ethers.utils.hexZeroPad( - PERMISSIONS.SETDATA + PERMISSIONS.CALL, - 32 - ); - await universalProfile1 - .connect(owner) - .setData([ADDRESS.PERMISSIONS + URDrevert.address.substr(2)], [URDRevertPermissions]); - - // switch account management to keyManager1 - await universalProfile1.connect(owner).transferOwnership(keyManager1.address); - - // fund UP with ether - await owner.sendTransaction({ - to: universalProfile1.address, - value: ethers.utils.parseEther("10"), - }); - - // FOR UNIVERSALPROFILE 2 - - // owner2 permission - - await universalProfile2 - .connect(owner2) - .setData([ADDRESS.PERMISSIONS + owner2.address.substr(2)], [ALL_PERMISSIONS_SET]); - - // set the URD Key - await universalProfile2 - .connect(owner2) - .setData([UNIVERSALRECEIVER_KEY], [universalReceiverDelegate2.address]); - - // set URD permissions - let URDPermissions2 = ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32); - await universalProfile2 - .connect(owner2) - .setData( - [ADDRESS.PERMISSIONS + universalReceiverDelegate2.address.substr(2)], - [URDPermissions2] - ); - - // set URDRevert permissions - - let URDRevertPermissions2 = ethers.utils.hexZeroPad( - PERMISSIONS.SETDATA + PERMISSIONS.CALL, - 32 - ); - await universalProfile2 - .connect(owner2) - .setData([ADDRESS.PERMISSIONS + URDrevert.address.substr(2)], [URDRevertPermissions2]); - - // switch account management to keyManager2 - await universalProfile2.connect(owner2).transferOwnership(keyManager2.address); - - // fund UP with ether - await owner2.sendTransaction({ - to: universalProfile2.address, - value: ethers.utils.parseEther("10"), - }); - }); - - beforeEach(async () => { - universalProfile1.connect(owner.address); - keyManager1.connect(owner.address); - universalProfile2.connect(owner2.address); - keyManager2.connect(owner2.address); - }); - - it("Should read ISLP1 Delegate interface id", async () => { - const interfaceID = "0xc2d7bcc1"; - const result = await universalReceiverDelegate1.callStatic.supportsInterface(interfaceID); - const resultSecond = await universalReceiverDelegate2.callStatic.supportsInterface( - interfaceID - ); - - expect(result).toBeTruthy(); - expect(resultSecond).toBeTruthy(); - }); - - it("Deploys correctly, and compare owners", async () => { - const idOwner = await universalProfile1.callStatic.owner(); - expect(idOwner).toEqual(keyManager1.address); - const idOwnerSecond = await universalProfile2.callStatic.owner(); - expect(idOwnerSecond).toEqual(keyManager2.address); - }); - - it("Should be able to read UR key", async () => { - // UP1 - const [gettedAddress] = await universalProfile1 - .connect(owner) - .getData([UNIVERSALRECEIVER_KEY]); - expect(await ethers.utils.getAddress(gettedAddress)).toEqual( - universalReceiverDelegate1.address - ); - // UP2 - const [gettedAddressSecond] = await universalProfile2 - .connect(owner2) - .getData([UNIVERSALRECEIVER_KEY]); - expect(await ethers.utils.getAddress(gettedAddressSecond)).toEqual( - universalReceiverDelegate2.address - ); - }); - - it("ensures owner is still universalProfile1's admin (=all permissions)", async () => { - let [permissions] = await universalProfile1.getData([ - ADDRESS.PERMISSIONS + owner.address.substr(2), - ]); - expect(permissions).toEqual( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "Owner should have all permissions set" - ); - - // UP2 - let [permissionsSecond] = await universalProfile2.getData([ - ADDRESS.PERMISSIONS + owner2.address.substr(2), - ]); - expect(permissionsSecond).toEqual( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "Owner should have all permissions set" - ); - }); - - it("get URD permissions", async () => { - let [permissions] = await universalProfile1.getData([ - ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2), - ]); - expect(permissions).toEqual( - "0x0000000000000000000000000000000000000000000000000000000000000018", - "URD should have permissions" - ); // to setData and call - - // UP2 - let [permissionsSecond] = await universalProfile2.getData([ - ADDRESS.PERMISSIONS + universalReceiverDelegate2.address.substr(2), - ]); - expect(permissionsSecond).toEqual( - "0x0000000000000000000000000000000000000000000000000000000000000018", - "URD should have permissions" - ); // to setData and call - }); - - it("Owner should be allowed to change keys", async () => { - // change universalReceiverDelegate1's permissions - let key = ADDRESS.PERMISSIONS + universalReceiverDelegate1.address.substr(2); - - let payload = universalProfile1.interface.encodeFunctionData("setData", [ - [key], - [PERMISSIONS.SETDATA], - ]); - - let result = await keyManager1.connect(owner).callStatic.execute(payload); - expect(result).toBeTruthy(); - - await keyManager1.connect(owner).execute(payload); - let fetchedResult = await universalProfile1.callStatic.getData([key]); - expect(Number(fetchedResult)).toEqual(PERMISSIONS.SETDATA); - - // reset universalReceiverDelegate1 permissions - await keyManager1.execute( - universalProfile1.interface.encodeFunctionData("setData", [ - [key], - [ethers.utils.hexZeroPad(PERMISSIONS.SETDATA + PERMISSIONS.CALL, 32)], - ]) - ); - }); - describe("Recepient Hook", () => { - beforeAll(async () => { - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID1, - false, - "0x34", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - it("=> Should Register the Asset Map for Token A with index 0 and interface Id", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("=> Should Register the Length of The Array : `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // length of the array is 1 - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token A in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenA.address); - }); - - it("=> Should Have the Second Key in the Array empty for now", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Transfer Token B", async () => { - let abi = tokenB.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID2, - false, - "0x32", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenB.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Register the Asset Map for Token B with index 1 and interface Id", async () => { - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Should Register the Address of Token B in the Second Key in the Array", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenB.address); - }); - - it("=> Safety Check for all Registred tokens", async () => { - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token B - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + B) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenB.address); - }); - - it("=> Should Have the Third Key in the Array empty for now", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Transfer Token C", async () => { - let abi = tokenC.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID3, - false, - "0x34", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenC.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Register the Asset Map for Token C with index 2 and interface Id", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000002" + INTERFACE_ID); - }); - - it("=> Should Update the Length of The Array to `3`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000003" - ); - }); - - it("=> Should Register the Address of Token C in the Third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - }); - - describe("Sender Hook", () => { - it("=> Eliminating Token B", async () => { - let abi = tokenB.interface.encodeFunctionData("burn", [TOKEN_ID2, "0x43"]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenB.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Item 2 in the LSP5ASSET Array Should be the address of Token C", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - - it("=> Item 3 Should not exist", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - - expect(gettedResult).toEqual("0x"); - }); - - it("=> Asset Map for Token B should not exist anymore", async () => { - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenBMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Asset Map for Token C refer to index 1 now", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - }); - - describe("Testing adding and eliminating behavior", () => { - it("Receive new token D", async () => { - let abi = tokenD.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID4, - false, - "0x43", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `3`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000003" - ); - }); - - it("=> Should Register the Address of Token D in the third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenD.address); - }); - - it("=> Asset Map for Token D refer to index 2 now", async () => { - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000002" + INTERFACE_ID); - }); - - it("=> Eliminating Token D", async () => { - let abi = tokenD.interface.encodeFunctionData("burn", [TOKEN_ID4, "0x22"]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `2`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - }); - - it("=> Asset Map for Token D should be empty now", async () => { - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token D from the third Key in the Array", async () => { - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item3_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Next slot should be empty", async () => { - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item4_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Safety Check for Token A and C", async () => { - // LSP5MAP for Token A - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult0 = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult0[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - - // LSP5MAP for Token C - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult1 = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult1[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - - // LSP5Array Length equal 2 (Token A + C) - let gettedResult2 = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult2[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult3] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult3)).toEqual(tokenA.address); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult4] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - - expect(await ethers.utils.getAddress(gettedResult4)).toEqual(tokenC.address); - }); - - it("=> Next slot should be empty", async () => { - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item4_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Eliminating Token A", async () => { - let abi = tokenA.interface.encodeFunctionData("burn", [TOKEN_ID1, "0x22"]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Asset Map for Token A should be empty now", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token A from the first Key in the Array and replace it with token C", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenC.address); - }); - - it("=> Next slot should be empty", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Eliminating Token C", async () => { - let abi = tokenC.interface.encodeFunctionData("burn", [TOKEN_ID3, "0x11"]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenC.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `0`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000000" - ); - }); - - it("=> Asset Map for Token C should be empty now", async () => { - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenCMapAsset]); - - expect(gettedResult[0]).toEqual("0x"); - }); - - it("=> Should remove the Address of Token C from the first Key ", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Next slot should be empty", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item2_Array_Key]); - expect(gettedResult).toEqual("0x"); - }); - - it("=> Keys Should be Empty", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - const item5_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000004"; - const Items = [ - item1_Array_Key, - item2_Array_Key, - item3_Array_Key, - item4_Array_Key, - item5_Array_Key, - ]; - let gettedResult = await universalProfile1.connect(owner).getData(Items); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x", "0x"]); - }); - - it("=> Token AssetMap Should be Empty", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - const AssetMap = [tokenAMapAsset, tokenBMapAsset, tokenCMapAsset, tokenDMapAsset]; - let gettedResult = await universalProfile1.connect(owner).getData(AssetMap); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x"]); - }); - - it("Receive token A again ", async () => { - let abi = tokenA.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID1, - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token A in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenA.address); - }); - - it("=> Asset Map for Token A refer to index 0 ", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenAMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Eliminate token A again ", async () => { - let abi = tokenA.interface.encodeFunctionData("burn", [TOKEN_ID1, "0x22"]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenA.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("Receive token E ", async () => { - let abi = tokenE.interface.encodeFunctionData("mint", [ - universalProfile1.address, - TOKEN_ID5, - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenE.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("=> Should Update the Length of The Array to `1`", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - }); - - it("=> Should Register the Address of Token E in the first Key in the Array", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult)).toEqual(tokenE.address); - }); - - it("=> Asset Map for Token E refer to index 0 ", async () => { - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("=> Keys Should be Empty bur first Key should exist", async () => { - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - const item3_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002"; - const item4_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003"; - const item5_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000004"; - const Items = [item2_Array_Key, item3_Array_Key, item4_Array_Key, item5_Array_Key]; - let gettedResult = await universalProfile1.connect(owner).getData(Items); - expect(gettedResult).toEqual(["0x", "0x", "0x", "0x"]); - - let [gettedAsset] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedAsset)).toEqual(tokenE.address); - }); - - it("=> Token AssetMap Should be Empty but for E should exist", async () => { - const tokenAMapAsset = LSP5_ASSET_MAP_HASH + tokenA.address.substr(2); - const tokenBMapAsset = LSP5_ASSET_MAP_HASH + tokenB.address.substr(2); - const tokenCMapAsset = LSP5_ASSET_MAP_HASH + tokenC.address.substr(2); - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - const AssetMap = [tokenAMapAsset, tokenBMapAsset, tokenCMapAsset, tokenDMapAsset]; - let gettedMaps = await universalProfile1.connect(owner).getData(AssetMap); - expect(gettedMaps).toEqual(["0x", "0x", "0x", "0x"]); - - let gettedResult = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - - describe("Transfering tokens between 2 UP", () => { - it("Should transfer TOKEN_ID5 of tokensE to UP2", async () => { - let abi = tokenE.interface.encodeFunctionData("transfer", [ - universalProfile1.address, - universalProfile2.address, - TOKEN_ID5, - false, - "0x22", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenE.address, - 0, - abi, - ]); - await keyManager1.execute(abiExecutor, { from: owner.address }); - }); - - it("Shouldnt keep All keys in UP1 intact", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000000" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(gettedResult1).toEqual("0x"); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x"); - }); - - it("Check if keys are registred after sending tokens in UP2", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenE.address); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Keys in UP2 Should be registred", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenE.address); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - - it("Next slot should be intact in UP2", async () => { - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(gettedResult1).toEqual("0x"); - }); - - it("Should clear keys from UP1 as balance of tokensE is 0", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000000" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(gettedResult1).toEqual("0x"); - - const tokenEMapAsset = LSP5_ASSET_MAP_HASH + tokenE.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenEMapAsset]); - - expect(gettedResult2[0]).toEqual("0x"); - }); - - it("Mint tokensD to UP2", async () => { - let abi = tokenD.interface.encodeFunctionData("mint", [ - universalProfile2.address, - TOKEN_ID4, - false, - "0x11", - ]); - let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager2.connect(owner2).execute(abiExecutor); - }); - - it("Check if keys are registred after sending tokensD in UP2", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000002" - ); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000001" + INTERFACE_ID); - }); - - it("Should Transfer tokenD from UP2 to UP1: clear tokenD from UP2 and register it in UP1", async () => { - let abi = tokenD.interface.encodeFunctionData("transfer", [ - universalProfile2.address, - universalProfile1.address, - TOKEN_ID4, - false, - "0x11", - ]); - let abiExecutor = universalProfile2.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await keyManager2.connect(owner2).execute(abiExecutor); - }); - - it("Should remove tokenD keys after sending tokensD from UP2 to UP1", async () => { - let gettedResult = await universalProfile2.connect(owner2).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item2_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001"; - let [gettedResult1] = await universalProfile2.connect(owner2).getData([item2_Array_Key]); - expect(gettedResult1).toEqual("0x"); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile2.connect(owner2).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x"); - }); - - it("Should regsiter tokenD keys after sending tokensD from UP2 to UP1", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - - describe("Implementing URD that reverts", () => { - beforeAll(async () => { - let abiSetData = universalProfile2.interface.encodeFunctionData("setData", [ - [UNIVERSALRECEIVER_KEY], - [URDrevert.address], - ]); - await keyManager2.connect(owner2).execute(abiSetData, { from: owner2.address }); - }); - - it("Should revert when sending tokens to UP2 (Transfer Function that have the hook after deducting amount)", async () => { - let abi = tokenD.interface.encodeFunctionData("transfer", [ - universalProfile1.address, - universalProfile2.address, - TOKEN_ID4, - false, - "0x11", - ]); - let abiExecutor = universalProfile1.interface.encodeFunctionData("execute", [ - OPERATIONS.CALL, - tokenD.address, - 0, - abi, - ]); - await expect(keyManager1.execute(abiExecutor)).toBeRevertedWith("This Contract reverts"); - }); - - it("Should check that token didn't get send", async () => { - let gettedResult = await universalProfile1.connect(owner).getData([LSP5_ARRAY_HASH]); - // - expect(gettedResult[0]).toEqual( - "0x" + "0000000000000000000000000000000000000000000000000000000000000001" - ); - - const item1_Array_Key = - "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000"; - let [gettedResult1] = await universalProfile1.connect(owner).getData([item1_Array_Key]); - expect(await ethers.utils.getAddress(gettedResult1)).toEqual(tokenD.address); - - const tokenDMapAsset = LSP5_ASSET_MAP_HASH + tokenD.address.substr(2); - - let gettedResult2 = await universalProfile1.connect(owner).getData([tokenDMapAsset]); - - expect(gettedResult2[0]).toEqual("0x" + "0000000000000000" + INTERFACE_ID); - }); - }); - }); -}); diff --git a/tests/utils/constants.ts b/tests/utils/constants.ts index d43330475..ae752ac01 100644 --- a/tests/utils/constants.ts +++ b/tests/utils/constants.ts @@ -39,3 +39,65 @@ export const UNIVERSALRECEIVER_KEY = export const RANDOM_BYTES32 = "0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b"; export const ERC777TokensRecipient = "0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b"; + +// LSP5-Received Assets + +export const RAW_INTERFACE_ID = { + LSP7: "e33f65c3", + LSP8: "49399145" +} + +export const LSP5_ASSET_MAP_HASH = "0x812c4334633eb81600000000"; + + +export const LSP5_ARRAY_KEY = + "0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b"; // keccak256("LSPASSETS[]") + +export const ITEMS_ARRAY_KEY = { + ITEM1: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000000", + ITEM2: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000001", + ITEM3: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000002", + ITEM4: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000003", + ITEM5: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000004", + ITEM6: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000005", + ITEM7: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000006", + ITEM8: "0x6460ee3c0aac563ccbf76d6e1d07bada00000000000000000000000000000007", +}; + +// bytes8 index +export const INDEX = { + ZERO: "0000000000000000", + ONE: "0000000000000001", + TWO: "0000000000000002", + THREE: "0000000000000003", + FOUR: "0000000000000004", + FIVE: "0000000000000005", + SIX: "0000000000000006", + SEVEN: "0000000000000007", +} + +// bytes32 arraylength + +export const ARRAY_LENGTH = { + ZERO: "0x0000000000000000000000000000000000000000000000000000000000000000", + ONE: "0x0000000000000000000000000000000000000000000000000000000000000001", + TWO: "0x0000000000000000000000000000000000000000000000000000000000000002", + THREE: "0x0000000000000000000000000000000000000000000000000000000000000003", + FOUR: "0x0000000000000000000000000000000000000000000000000000000000000004", + FIVE: "0x0000000000000000000000000000000000000000000000000000000000000005", + SIX: "0x0000000000000000000000000000000000000000000000000000000000000006", + SEVEN: "0x0000000000000000000000000000000000000000000000000000000000000007", + EIGHT: "0x0000000000000000000000000000000000000000000000000000000000000008", +} + +// Random Token Id +export const TOKEN_ID = { + ONE: "0xad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a5", + TWO: "0xd4d1a59767271eefdc7830a772b9732a11d503531d972ab8c981a6b1c0e666e5", + THREE: "0x3672b35640006da199633c5c75015da83589c4fb84ef8276b18076529e3d3196", + FOUR: "0x80a6c6138772c2d7c710a3d49f4eea603028994b7e390f670dd68566005417f0", + FIVE: "0x5c6f8b1aed769a328dad1ae15220e93730cdd52cb12817ae5fd8c15023d660d3", + SIX: "0x65ce3c3668a850c4f9fce91762a3fb886380399f02a9eb1495055234e7c0287a", + SEVEN: "0x00121ee2bd9802ce88a413ac1851c8afe6fe7474fb5d1b7da4475151b013da53", + EIGHT: "0x367f9d97f8dd1bece61f8b74c5db7616958147682674fd32de73490bd6347f60" +}