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" ;
26import { CreateSellerArgs } from "./../../packages/common/src/types/accounts" ;
37import { CreateOfferArgs } from "./../../packages/common/src/types/offers" ;
48import {
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
1014import { mockCreateOfferArgs } from "../../packages/common/tests/mocks" ;
1115import { 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
3241const seedWallet = seedWallet4 ; // be sure the seedWallet is not used by another test (to allow concurrent run)
3342const 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
0 commit comments