From ff753b3010875632b7193fdb1fee967b3a5dfaab Mon Sep 17 00:00:00 2001 From: Boldizsar Mezei Date: Thu, 7 Sep 2023 20:33:48 +0200 Subject: [PATCH] Allow parallel nft purchase with OTR Fixes --- ...ions_tangle-online-unit-tests_emulator.yml | 120 ++++++++++------ .../workflows/functions_tangle-unit-tests.yml | 130 +++++++++++------- .../nft/nft-purchase.service.ts | 10 +- .../test-tangle/minted-nft-trading/Helper.ts | 34 ++++- .../minted-nft-trading_10.spec.ts | 82 +++++++++++ .../minted-nft-trading_11.spec.ts | 108 +++++++++++++++ 6 files changed, 387 insertions(+), 97 deletions(-) create mode 100644 packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts create mode 100644 packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts diff --git a/.github/workflows/functions_tangle-online-unit-tests_emulator.yml b/.github/workflows/functions_tangle-online-unit-tests_emulator.yml index c8ae7df152..50dbe43d94 100644 --- a/.github/workflows/functions_tangle-online-unit-tests_emulator.yml +++ b/.github/workflows/functions_tangle-online-unit-tests_emulator.yml @@ -1351,7 +1351,7 @@ jobs: firebase emulators:exec " npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_3.spec.ts && npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_2.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_1.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1386,9 +1386,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_5.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_4.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_3.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_1.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1423,9 +1423,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_2.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_1.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_9.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_4.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_3.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1460,9 +1460,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_8.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_7.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_6.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_1.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_9.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_8.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1497,9 +1497,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_5.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_4.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_3.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_7.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_6.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1534,9 +1534,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_2.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_12.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_11.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_4.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_3.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1571,9 +1571,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_10.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_1.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_7.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_12.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_11.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_10.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1608,9 +1608,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_6.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_5.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_4.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_1.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_7.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_6.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1645,9 +1645,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_3.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_2.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_12.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_5.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_4.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_3.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1682,9 +1682,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_10.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_1.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_6.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_2.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_12.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_10.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1719,9 +1719,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_5.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_4.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_3.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_1.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_6.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1756,9 +1756,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_2.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_1.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_9.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_4.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_3.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1793,9 +1793,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_8.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_7.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_6.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_1.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_9.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_8.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1830,9 +1830,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_5.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_4.spec.ts && - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_3.spec.ts + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_7.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_6.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1867,7 +1867,43 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_2.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_4.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_3.spec.ts && + npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_2.spec.ts + " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data + - name: Archive firestore data + uses: actions/upload-artifact@v3 + if: ${{ failure() }} + with: + name: firestore-data-test-tangle-online-chunk_49 + path: ./packages/functions/firestore-data/ + retention-days: 1 + chunk_50: + needs: npm-install + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + - uses: actions/cache@v3 + with: + path: | + node_modules + packages/functions/node_modules + packages/interfaces/node_modules + key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }} + - name: Init + run: | + npm run build:functions + npm install -g firebase-tools + - name: Test + working-directory: packages/functions + run: | + export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" + npm run milestone-sync & + firebase emulators:exec " npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_10.spec.ts && npm run test-tangle-online:ci -- --findRelatedTests test-tangle/award/award_1.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data @@ -1875,6 +1911,6 @@ jobs: uses: actions/upload-artifact@v3 if: ${{ failure() }} with: - name: firestore-data-test-tangle-online-chunk_49 + name: firestore-data-test-tangle-online-chunk_50 path: ./packages/functions/firestore-data/ retention-days: 1 diff --git a/.github/workflows/functions_tangle-unit-tests.yml b/.github/workflows/functions_tangle-unit-tests.yml index 8147eb77b2..75f021a4c1 100644 --- a/.github/workflows/functions_tangle-unit-tests.yml +++ b/.github/workflows/functions_tangle-unit-tests.yml @@ -1349,7 +1349,7 @@ jobs: firebase emulators:exec " npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_3.spec.ts && npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_1.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1384,9 +1384,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_5.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_4.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_3.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-nft-trading/minted-nft-trading_1.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1421,9 +1421,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_1.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_9.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_4.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_3.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1458,9 +1458,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_8.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_7.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_6.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/metadata-nft/mint-metadata-nft_1.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_9.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_8.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1495,9 +1495,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_5.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_4.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_3.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_7.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_6.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1532,9 +1532,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_12.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_11.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_4.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_3.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1569,9 +1569,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_10.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_1.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_7.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_12.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_11.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_10.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1606,9 +1606,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_6.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_5.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_4.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/collection-minting/collection-minting_1.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_7.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_6.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1643,9 +1643,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_3.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_12.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_5.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_4.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_3.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1680,9 +1680,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_10.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_1.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_6.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_2.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_12.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_10.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1717,9 +1717,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_5.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_4.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_3.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_1.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_6.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1754,9 +1754,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_1.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_9.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_4.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_3.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1791,9 +1791,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_8.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_7.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_6.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/award-tangle/award-tangle_1.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_9.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_8.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1828,9 +1828,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_5.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_4.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_3.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_7.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_6.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_5.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1865,9 +1865,9 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_2.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_10.spec.ts && - npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_1.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_4.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_3.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_2.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1902,7 +1902,8 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-token-trade/minted-token-trade_15.only.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_10.spec.ts && + npm run test-tangle:ci -- --findRelatedTests test-tangle/award/award_1.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1937,7 +1938,7 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_9.only.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/minted-token-trade/minted-token-trade_15.only.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -1972,7 +1973,7 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_8.only.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_9.only.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -2007,7 +2008,7 @@ jobs: export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" npm run milestone-sync & firebase emulators:exec " - npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_11.only.spec.ts + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_8.only.spec.ts " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data - name: Archive firestore data uses: actions/upload-artifact@v3 @@ -2016,3 +2017,38 @@ jobs: name: firestore-data-test-tangle-chunk_53 path: ./packages/functions/firestore-data/ retention-days: 1 + chunk_54: + needs: npm-install + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16.x + - uses: actions/cache@v3 + with: + path: | + node_modules + packages/functions/node_modules + packages/interfaces/node_modules + key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }} + - name: Init + run: | + npm run build:functions + npm install -g firebase-tools + - name: Test + working-directory: packages/functions + run: | + export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json" + npm run milestone-sync & + firebase emulators:exec " + npm run test-tangle:ci -- --findRelatedTests test-tangle/base-token-trading/base-token-trading_11.only.spec.ts + " --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data + - name: Archive firestore data + uses: actions/upload-artifact@v3 + if: ${{ failure() }} + with: + name: firestore-data-test-tangle-chunk_54 + path: ./packages/functions/firestore-data/ + retention-days: 1 diff --git a/packages/functions/src/services/payment/tangle-service/nft/nft-purchase.service.ts b/packages/functions/src/services/payment/tangle-service/nft/nft-purchase.service.ts index fb88eb9d3c..a3684756ec 100644 --- a/packages/functions/src/services/payment/tangle-service/nft/nft-purchase.service.ts +++ b/packages/functions/src/services/payment/tangle-service/nft/nft-purchase.service.ts @@ -53,7 +53,7 @@ export class TangleNftPurchaseService { ): Promise => { const params = await assertValidationAsync(nftPurchaseSchema, request); - const order = await createNftPuchaseOrder(params.collection, params.nft, owner); + const order = await createNftPuchaseOrder(params.collection, params.nft, owner, '', true); order.payload.tanglePuchase = true; order.payload.disableWithdraw = params.disableWithdraw || false; @@ -99,6 +99,7 @@ export const createNftPuchaseOrder = async ( nftId: string | undefined, owner: string, ip = '', + allowParallelPurchasing = false, ): Promise => { const collection = await getCollection(collectionId); const space = (await getSpace(collection.space))!; @@ -111,7 +112,7 @@ export const createNftPuchaseOrder = async ( await assertIpNotBlocked(ip, nft.uid, 'nft'); } - await assertNftCanBePurchased(space, collection, nft, nftId, owner); + await assertNftCanBePurchased(space, collection, nft, nftId, owner, allowParallelPurchasing); const currentOwner = nft.owner ? await getMember(nft.owner) : space; assertCurrentOwnerAddress(currentOwner, nft); @@ -238,6 +239,7 @@ const assertNftCanBePurchased = async ( nft: Nft, nftIdParam: string | undefined, owner: string, + allowParallelPurchasing: boolean, ) => { if (collection.type !== CollectionType.CLASSIC && nftIdParam && !nft.owner) { throw invalidArgument(WenError.generated_spf_nft_must_be_sold_first); @@ -279,7 +281,9 @@ const assertNftCanBePurchased = async ( throw invalidArgument(WenError.nft_does_not_belong_to_collection); } - await assertNoOrderInProgress(owner); + if (!allowParallelPurchasing) { + await assertNoOrderInProgress(owner); + } }; const assertUserHasAccess = (space: Space, collection: Collection, owner: string) => diff --git a/packages/functions/test-tangle/minted-nft-trading/Helper.ts b/packages/functions/test-tangle/minted-nft-trading/Helper.ts index daac4f5ebb..9876aba678 100644 --- a/packages/functions/test-tangle/minted-nft-trading/Helper.ts +++ b/packages/functions/test-tangle/minted-nft-trading/Helper.ts @@ -13,6 +13,8 @@ import { NftStatus, Space, Timestamp, + Transaction, + TransactionType, UnsoldMintingOptions, } from '@build-5/interfaces'; import dayjs from 'dayjs'; @@ -25,6 +27,8 @@ import { import { createNft, orderNft, setForSaleNft } from '../../src/runtime/firebase/nft/index'; import { NftWallet } from '../../src/services/wallet/NftWallet'; import { SmrWallet } from '../../src/services/wallet/SmrWalletService'; +import { AddressDetails } from '../../src/services/wallet/wallet'; +import { serverTime } from '../../src/utils/dateTime.utils'; import * as wallet from '../../src/utils/wallet.utils'; import { createMember as createMemberTest, @@ -123,12 +127,11 @@ export class Helper { return this.nft; }; - public setAvailableForAuction = async () => { - mockWalletReturnValue(this.walletSpy, this.guardian!, this.dummyAuctionData(this.nft!.uid)); + public setAvailableForAuction = async (nft?: string) => { + const uid = nft || this.nft?.uid!; + mockWalletReturnValue(this.walletSpy, this.guardian!, this.dummyAuctionData(uid)); await testEnv.wrap(setForSaleNft)({}); - await wait( - async () => (await build5Db().doc(`${COL.NFT}/${this.nft!.uid}`).get())?.available === 3, - ); + await wait(async () => (await build5Db().doc(`${COL.NFT}/${uid}`).get())?.available === 3); }; public setAvailableForSale = async () => { @@ -182,4 +185,25 @@ export class Helper { availableFrom: dayjs().toDate(), access: NftAccess.OPEN, }); + + public sendNftToAddress = async ( + sourceAddress: AddressDetails, + targetAddressBech32: string, + nftId: string, + ) => { + const order: Transaction = { + type: TransactionType.WITHDRAW_NFT, + uid: wallet.getRandomEthAddress(), + member: this.guardian, + createdOn: serverTime(), + network: this.network, + payload: { + sourceAddress: sourceAddress.bech32, + targetAddress: targetAddressBech32, + nftId, + }, + }; + await build5Db().doc(`${COL.TRANSACTION}/${order.uid}`).create(order); + return order.uid; + }; } diff --git a/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts b/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts new file mode 100644 index 0000000000..8e356c06aa --- /dev/null +++ b/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_10.spec.ts @@ -0,0 +1,82 @@ +import { + COL, + MIN_IOTA_AMOUNT, + Network, + Nft, + NftPurchaseTangleRequest, + TangleRequestType, + Transaction, +} from '@build-5/interfaces'; +import { build5Db } from '../../src/firebase/firestore/build5Db'; +import { MnemonicService } from '../../src/services/wallet/mnemonic'; +import { wait } from '../../test/controls/common'; +import { getTangleOrder } from '../common'; +import { awaitLedgerInclusionState, requestFundsFromFaucet } from '../faucet'; +import { Helper } from './Helper'; + +describe('Minted nft trading', () => { + const helper = new Helper(); + let tangleOrder: Transaction; + + beforeAll(async () => { + await helper.beforeAll(); + tangleOrder = await getTangleOrder(); + }); + + beforeEach(async () => { + await helper.beforeEach(); + }); + + it('Should buy 2 nft in parallel', async () => { + const address = await helper.walletService!.getNewIotaAddressDetails(); + await requestFundsFromFaucet(Network.RMS, address.bech32, 5 * MIN_IOTA_AMOUNT); + + let nft1 = await helper.createAndOrderNft(); + let nft2 = await helper.createAndOrderNft(); + + await helper.mintCollection(); + + await helper.setAvailableForAuction(nft1.uid); + await helper.setAvailableForAuction(nft2.uid); + + const blockId = await helper.walletService!.send( + address, + tangleOrder.payload.targetAddress!, + MIN_IOTA_AMOUNT, + { + customMetadata: { + request: { + requestType: TangleRequestType.NFT_PURCHASE, + collection: helper.collection, + nft: nft1.uid, + disableWithdraw: true, + } as NftPurchaseTangleRequest, + }, + }, + ); + await MnemonicService.store(address.bech32, address.mnemonic, Network.RMS); + + await awaitLedgerInclusionState(blockId, tangleOrder.network); + + await helper.walletService!.send(address, tangleOrder.payload.targetAddress!, MIN_IOTA_AMOUNT, { + customMetadata: { + request: { + requestType: TangleRequestType.NFT_PURCHASE, + collection: helper.collection, + nft: nft2.uid, + disableWithdraw: true, + } as NftPurchaseTangleRequest, + }, + }); + await MnemonicService.store(address.bech32, address.mnemonic, Network.RMS); + + const nftDocRef1 = build5Db().doc(`${COL.NFT}/${nft1.uid}`); + const nftDocRef2 = build5Db().doc(`${COL.NFT}/${nft2.uid}`); + + await wait(async () => { + nft1 = (await nftDocRef1.get())!; + nft2 = (await nftDocRef2.get())!; + return nft1?.owner === address.bech32 && nft2?.owner === address.bech32; + }); + }); +}); diff --git a/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts b/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts new file mode 100644 index 0000000000..1b604cba9b --- /dev/null +++ b/packages/functions/test-tangle/minted-nft-trading/minted-nft-trading_11.spec.ts @@ -0,0 +1,108 @@ +import { + COL, + MIN_IOTA_AMOUNT, + Network, + Nft, + NftPurchaseTangleRequest, + NftStatus, + TangleRequestType, + Transaction, + TransactionType, +} from '@build-5/interfaces'; +import { build5Db } from '../../src/firebase/firestore/build5Db'; +import { MnemonicService } from '../../src/services/wallet/mnemonic'; +import { wait } from '../../test/controls/common'; +import { getTangleOrder } from '../common'; +import { awaitLedgerInclusionState, requestFundsFromFaucet } from '../faucet'; +import { Helper } from './Helper'; + +describe('Minted nft trading', () => { + const helper = new Helper(); + let tangleOrder: Transaction; + + beforeAll(async () => { + await helper.beforeAll(); + tangleOrder = await getTangleOrder(); + }); + + beforeEach(async () => { + await helper.beforeEach(); + }); + + it('Should buy 2 nft in parallel, and deposit in parallel', async () => { + const address = await helper.walletService!.getNewIotaAddressDetails(); + await requestFundsFromFaucet(Network.RMS, address.bech32, 5 * MIN_IOTA_AMOUNT); + + let nft1 = await helper.createAndOrderNft(); + let nft2 = await helper.createAndOrderNft(); + + await helper.mintCollection(); + + await helper.setAvailableForAuction(nft1.uid); + await helper.setAvailableForAuction(nft2.uid); + + const blockId = await helper.walletService!.send( + address, + tangleOrder.payload.targetAddress!, + MIN_IOTA_AMOUNT, + { + customMetadata: { + request: { + requestType: TangleRequestType.NFT_PURCHASE, + collection: helper.collection, + nft: nft1.uid, + } as NftPurchaseTangleRequest, + }, + }, + ); + await MnemonicService.store(address.bech32, address.mnemonic, Network.RMS); + + await awaitLedgerInclusionState(blockId, tangleOrder.network); + + await helper.walletService!.send(address, tangleOrder.payload.targetAddress!, MIN_IOTA_AMOUNT, { + customMetadata: { + request: { + requestType: TangleRequestType.NFT_PURCHASE, + collection: helper.collection, + nft: nft2.uid, + } as NftPurchaseTangleRequest, + }, + }); + await MnemonicService.store(address.bech32, address.mnemonic, Network.RMS); + + const nftDocRef1 = build5Db().doc(`${COL.NFT}/${nft1.uid}`); + const nftDocRef2 = build5Db().doc(`${COL.NFT}/${nft2.uid}`); + nft1 = (await nftDocRef1.get())!; + nft2 = (await nftDocRef2.get())!; + + const query = build5Db() + .collection(COL.TRANSACTION) + .where('type', '==', TransactionType.WITHDRAW_NFT) + .where('member', '==', address.bech32); + await wait(async () => { + const snap = await query.get(); + return ( + snap.length === 2 && + snap[0]?.payload?.walletReference?.confirmed && + snap[1]?.payload?.walletReference?.confirmed + ); + }); + + await helper.sendNftToAddress( + address, + tangleOrder.payload.targetAddress!, + nft1.mintingData?.nftId!, + ); + await helper.sendNftToAddress( + address, + tangleOrder.payload.targetAddress!, + nft2.mintingData?.nftId!, + ); + + await wait(async () => { + nft1 = (await nftDocRef1.get())!; + nft2 = (await nftDocRef2.get())!; + return nft1?.status === NftStatus.MINTED && nft2?.status === NftStatus.MINTED; + }); + }); +});