Skip to content

Commit b7d5342

Browse files
prepare new e2e test for getSellerByAddress() (deactivated for now)
1 parent 98aeef0 commit b7d5342

File tree

6 files changed

+385
-220
lines changed

6 files changed

+385
-220
lines changed

contracts/scripts/deploy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ async function main() {
168168
config[0].token = mockBosonToken.address;
169169
}
170170

171+
if (hre.network.name === "localhost") {
172+
console.log(`\n💎 Deploying mock LENS contract...`);
173+
const confirmations = 1;
174+
let lensTokenContractFactory = await ethers.getContractFactory(
175+
"MockNFTAuth721"
176+
);
177+
const lensTokenContract = await lensTokenContractFactory.deploy({
178+
gasLimit
179+
});
180+
await lensTokenContract.deployTransaction.wait(confirmations);
181+
deploymentComplete("LensToken", lensTokenContract.address, [], contracts);
182+
}
183+
171184
console.log(
172185
`\n💎 Deploying AccessController, ProtocolDiamond, and Diamond utility facets...`
173186
);

e2e/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919

2020
hardhat-node:
2121
build: ../contracts
22-
image: hardhat-node:a24305388c8a2b86cb59667e184677ab8862ebf2
22+
image: hardhat-node:a24305388c8a2b86cb59667e184677ab8862ebf5
2323
ports:
2424
- "8545:8545"
2525

e2e/tests/core-sdk.test.ts

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { DAY_IN_MS, DAY_IN_SEC } from "./../../packages/core-sdk/tests/mocks";
1+
import {
2+
DAY_IN_MS,
3+
DAY_IN_SEC,
4+
ZERO_ADDRESS
5+
} from "./../../packages/core-sdk/tests/mocks";
26
import { CreateSellerArgs } from "./../../packages/common/src/types/accounts";
37
import { CreateOfferArgs } from "./../../packages/common/src/types/offers";
48
import {
59
DisputeState,
610
ExchangeFieldsFragment
711
} from "./../../packages/core-sdk/src/subgraph";
8-
import { utils, constants, BigNumber, BigNumberish } from "ethers";
12+
import { utils, constants, BigNumber, BigNumberish, Wallet } from "ethers";
913

1014
import { mockCreateOfferArgs } from "../../packages/common/tests/mocks";
1115
import { CoreSDK } from "../../packages/core-sdk/src";
@@ -26,8 +30,13 @@ import {
2630
seedWallet5,
2731
seedWallet6,
2832
initCoreSDKWithWallet,
29-
drWallet
33+
drWallet,
34+
provider,
35+
ownerOfErc721Token,
36+
mintErc721Token
3037
} from "./utils";
38+
import { getDefaultConfig, AuthTokenType } from "@bosonprotocol/common";
39+
import { EthersAdapter } from "../../packages/ethers-sdk/src";
3140

3241
const seedWallet = seedWallet4; // be sure the seedWallet is not used by another test (to allow concurrent run)
3342
const sellerWallet2 = seedWallet5; // be sure the seedWallet is not used by another test (to allow concurrent run)
@@ -585,6 +594,107 @@ describe("core-sdk", () => {
585594
expect(seller2).toBeTruthy();
586595
expect(seller2.id).toEqual(sellerId);
587596
});
597+
598+
// This test requires a patch in the protocol-contracts submodule
599+
// --> MockNFTAuth721 to inherit from ERC721EnumerableUpgradeable instead of ERC721Upgradeable
600+
// (to be imported from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";)
601+
// Deactivate the test until the submodule is updated
602+
xtest("getSellerByAddress() retrieve the seller using the auth token", async () => {
603+
const { coreSDK, fundedWallet } = await initCoreSDKWithFundedWallet(
604+
seedWallet
605+
);
606+
607+
const tokenType = AuthTokenType.LENS; // LENS
608+
const defaultConfig = getDefaultConfig("local");
609+
const lensContract = defaultConfig.lens?.LENS_HUB_CONTRACT as string;
610+
const web3Lib = new EthersAdapter(provider, fundedWallet);
611+
const originalAddress = fundedWallet.address;
612+
613+
// find a tokenId that is not minted yet
614+
let tokenId = 123456789;
615+
let ownerOf = "NOT_ZERO_ADDRESS";
616+
while (ownerOf !== ZERO_ADDRESS) {
617+
try {
618+
ownerOf = await ownerOfErc721Token({
619+
tokenId: tokenId.toString(),
620+
contractAddress: lensContract,
621+
web3Lib
622+
});
623+
tokenId++;
624+
} catch {
625+
ownerOf = ZERO_ADDRESS;
626+
}
627+
}
628+
629+
// Check the (future) seller doesn't own any auth token yet
630+
let lensTokens = [] as string[];
631+
lensTokens = await coreSDK.fetchUserAuthTokens(
632+
originalAddress,
633+
tokenType
634+
);
635+
expect(lensTokens.length).toEqual(0);
636+
637+
// Mint the token in the mocked LENS contract for the future seller
638+
const tx = await mintErc721Token({
639+
to: originalAddress,
640+
tokenId: tokenId.toString(),
641+
contractAddress: lensContract,
642+
web3Lib
643+
});
644+
tx.wait();
645+
646+
// Check the (future) seller now owns an auth token
647+
lensTokens = await coreSDK.fetchUserAuthTokens(
648+
originalAddress,
649+
tokenType
650+
);
651+
expect(lensTokens.length).toEqual(1);
652+
653+
// Create the seller account, using originalAddress
654+
const seller = await createSeller(coreSDK, originalAddress);
655+
expect(seller).toBeTruthy();
656+
657+
// Create a new address
658+
const sellerId = seller.id;
659+
const newWallet = Wallet.createRandom().connect(provider);
660+
const newAddress = newWallet.address;
661+
662+
// Update the seller to assign the auth token and assign the new address to all accounts
663+
const updateSellerTx = await coreSDK.updateSeller({
664+
id: sellerId,
665+
operator: newAddress,
666+
admin: ZERO_ADDRESS, // need to be set to 0 when using auth token
667+
clerk: newAddress,
668+
treasury: newAddress,
669+
authTokenId: tokenId.toString(),
670+
authTokenType: tokenType
671+
});
672+
await updateSellerTx.wait();
673+
await waitForGraphNodeIndexing();
674+
675+
// Check the seller is found using the auth token
676+
const sellerAuthToken = await coreSDK.getSellerByAuthToken(
677+
tokenId.toString(),
678+
tokenType
679+
);
680+
expect(sellerAuthToken).toBeTruthy();
681+
expect(sellerAuthToken.id).toEqual(sellerId);
682+
683+
// Check the seller is NOT found using the previous address
684+
const operator = await coreSDK.getSellerByOperator(originalAddress);
685+
expect(operator).not.toBeTruthy();
686+
const admin = await coreSDK.getSellerByAdmin(originalAddress);
687+
expect(admin).not.toBeTruthy();
688+
const clerk = await coreSDK.getSellerByClerk(originalAddress);
689+
expect(clerk).not.toBeTruthy();
690+
const treasury = await coreSDK.getSellerByTreasury(originalAddress);
691+
expect(treasury).not.toBeTruthy();
692+
693+
// Check the seller is found using the generic method
694+
const seller2 = await coreSDK.getSellerByAddress(originalAddress);
695+
expect(seller2).toBeTruthy();
696+
expect(seller2.id).toEqual(sellerId);
697+
});
588698
});
589699
});
590700

e2e/tests/utils.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
import {
1010
CoreSDK,
1111
getDefaultConfig,
12-
accounts
12+
accounts,
13+
erc721
1314
} from "../../packages/core-sdk/src";
1415
import { IpfsMetadataStorage } from "../../packages/ipfs-storage/src";
1516
import { EthersAdapter } from "../../packages/ethers-sdk/src";
@@ -25,6 +26,7 @@ import {
2526
ACCOUNT_9,
2627
ACCOUNT_10
2728
} from "../../contracts/accounts";
29+
import { TransactionResponse, Web3LibAdapter } from "@bosonprotocol/common";
2830

2931
export const MOCK_ERC20_ADDRESS =
3032
getDefaultConfig("local").contracts.testErc20 ||
@@ -304,3 +306,32 @@ export async function createDisputeResolver(
304306
protocolAdminCoreSDK: coreSDK
305307
};
306308
}
309+
310+
export async function mintErc721Token(args: {
311+
to: string;
312+
tokenId: string;
313+
contractAddress: string;
314+
web3Lib: Web3LibAdapter;
315+
}): Promise<TransactionResponse> {
316+
const erc721Iface = erc721.iface.erc721Iface;
317+
318+
return args.web3Lib.sendTransaction({
319+
to: args.contractAddress,
320+
data: erc721Iface.encodeFunctionData("mint", [args.to, args.tokenId])
321+
});
322+
}
323+
324+
export async function ownerOfErc721Token(args: {
325+
tokenId: string;
326+
contractAddress: string;
327+
web3Lib: Web3LibAdapter;
328+
}): Promise<string> {
329+
const erc721Iface = erc721.iface.erc721Iface;
330+
const result = await args.web3Lib.call({
331+
to: args.contractAddress,
332+
data: erc721Iface.encodeFunctionData("ownerOf", [args.tokenId])
333+
});
334+
335+
const [owner] = erc721Iface.decodeFunctionResult("ownerOf", result);
336+
return String(owner);
337+
}

0 commit comments

Comments
 (0)