@@ -46,14 +46,14 @@ describe('web3telegram.sendTelegram()', () => {
4646 const iexecOptions = getTestIExecOption ( ) ;
4747 const prodWorkerpoolPublicPrice = 1000 ;
4848 const defaultConfig = getChainDefaultConfig ( DEFAULT_CHAIN_ID ) ;
49-
49+ const workerpoolprice = 1_000 ;
5050 beforeAll ( async ( ) => {
5151 // (default) prod workerpool (not free) always available
5252 await createAndPublishWorkerpoolOrder (
5353 TEST_CHAIN . prodWorkerpool ,
5454 TEST_CHAIN . prodWorkerpoolOwnerWallet ,
5555 NULL_ADDRESS ,
56- 1_000 ,
56+ workerpoolprice ,
5757 prodWorkerpoolPublicPrice
5858 ) ;
5959 // learn prod pool (free) assumed always available
@@ -613,4 +613,75 @@ describe('web3telegram.sendTelegram()', () => {
613613 } ) ;
614614 } ) ;
615615 } ) ;
616+
617+ describe ( 'allowDeposit' , ( ) => {
618+ let protectData : ProtectedDataWithSecretProps ;
619+ consumerWallet = getRandomWallet ( ) ;
620+ const dataPricePerAccess = 1000 ;
621+ let web3telegramConsumerInstance : IExecWeb3telegram ;
622+ beforeAll ( async ( ) => {
623+ protectData = await dataProtector . protectData ( {
624+ data : { telegram_chatId : '12345' } ,
625+ name : 'test do not use' ,
626+ } ) ;
627+ await dataProtector . grantAccess ( {
628+ authorizedApp : getChainDefaultConfig ( DEFAULT_CHAIN_ID ) . dappAddress ,
629+ protectedData : protectData . address ,
630+ authorizedUser : consumerWallet . address , // consumer wallet
631+ numberOfAccess : 1000 ,
632+ pricePerAccess : dataPricePerAccess ,
633+ } ) ;
634+ await waitSubgraphIndexing ( ) ;
635+ web3telegramConsumerInstance = new IExecWeb3telegram (
636+ ...getTestConfig ( consumerWallet . privateKey )
637+ ) ;
638+ } , 2 * MAX_EXPECTED_BLOCKTIME ) ;
639+ it (
640+ 'should throw error if insufficient total balance to cover task cost and allowDeposit is false' ,
641+ async ( ) => {
642+ let error ;
643+ try {
644+ await web3telegramConsumerInstance . sendTelegram ( {
645+ telegramContent : 'e2e telegram content for test' ,
646+ protectedData : protectData . address ,
647+ dataMaxPrice : dataPricePerAccess ,
648+ workerpoolMaxPrice : workerpoolprice ,
649+ allowDeposit : false ,
650+ } ) ;
651+ } catch ( err ) {
652+ error = err ;
653+ }
654+ expect ( error ) . toBeInstanceOf ( Web3TelegramWorkflowError ) ;
655+ expect ( error ) . toBeInstanceOf ( Error ) ;
656+ expect ( error . message ) . toBe ( 'Failed to sendTelegram' ) ;
657+ const causeMsg =
658+ error . errorCause ?. message ||
659+ error . cause ?. message ||
660+ error . cause ||
661+ error . errorCause ;
662+ expect ( causeMsg ) . toBe (
663+ `Cost per task (${
664+ dataPricePerAccess + workerpoolprice
665+ } ) is greater than requester account stake (0). Orders can't be matched. If you are the requester, you should deposit to top up your account`
666+ ) ;
667+ } ,
668+ 3 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
669+ ) ;
670+ it (
671+ 'should send telegram after depositing sufficient funds to cover task cost when allowDeposit is true' ,
672+ async ( ) => {
673+ const result = await web3telegramConsumerInstance . sendTelegram ( {
674+ telegramContent : 'e2e telegram content for test' ,
675+ protectedData : protectData . address ,
676+ dataMaxPrice : dataPricePerAccess ,
677+ workerpoolMaxPrice : workerpoolprice ,
678+ allowDeposit : true ,
679+ } ) ;
680+ expect ( result ) . toBeDefined ( ) ;
681+ expect ( result ) . toHaveProperty ( 'taskId' ) ;
682+ expect ( result ) . toHaveProperty ( 'dealId' ) ;
683+ } ,
684+ 3 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
685+ ) ;
686+ } ) ;
616687} ) ;
0 commit comments