Skip to content

Commit

Permalink
Merge pull request #2817 from build-5/bugfix/missing_nft_credit
Browse files Browse the repository at this point in the history
Credit tokens if nft was not sent
  • Loading branch information
adamunchained authored Feb 20, 2024
2 parents 5e67131 + 55a8e2e commit 5c63977
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 154 deletions.
184 changes: 110 additions & 74 deletions .github/workflows/functions_tangle-online-unit-tests_emulator.yml

Large diffs are not rendered by default.

190 changes: 113 additions & 77 deletions .github/workflows/functions_tangle-unit-tests.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PropStats,
Space,
Transaction,
TransactionPayloadType,
WenError,
} from '@build-5/interfaces';
import { NftOutput } from '@iota/sdk';
Expand Down Expand Up @@ -54,7 +55,11 @@ export class NftDepositService extends BaseService {
});
} catch (error) {
const payment = await this.transactionService.createPayment(order, match, true);
this.transactionService.createNftCredit(payment, match, error as Record<string, unknown>);
if (tranEntry.nftOutput) {
this.transactionService.createNftCredit(payment, match, error as Record<string, unknown>);
} else {
this.transactionService.createCredit(TransactionPayloadType.DEPOSIT_NFT, payment, match);
}
}
};

Expand All @@ -64,7 +69,7 @@ export class NftDepositService extends BaseService {
match: TransactionMatch,
) => {
if (!transactionEntry.nftOutput) {
throw WenError.invalid_params;
throw WenError.invalid_nft_id;
}
const nft = await getNftByMintingId(transactionEntry.nftOutput.nftId);
if (!nft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ export class NftStakeService extends BaseService {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
const payment = await this.transactionService.createPayment(order, match, true);
this.transactionService.createNftCredit(payment, match, error, customErrorParams);

if (tranEntry.nftOutput) {
this.transactionService.createNftCredit(payment, match, error, customErrorParams);
} else {
this.transactionService.createCredit(TransactionPayloadType.DEPOSIT_NFT, payment, match);
}

console.error('nft stake error', order.uid, payment.uid, error, customErrorParams);
}
};
Expand Down
50 changes: 50 additions & 0 deletions packages/functions/test-tangle/nft-staking/nft-staking_10.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { build5Db } from '@build-5/database';
import {
COL,
MIN_IOTA_AMOUNT,
Network,
StakeType,
Transaction,
TransactionType,
} from '@build-5/interfaces';
import { stakeNft } from '../../src/runtime/firebase/nft/index';
import { mockWalletReturnValue, wait } from '../../test/controls/common';
import { testEnv } from '../../test/set-up';
import { requestFundsFromFaucet } from '../faucet';
import { Helper } from './Helper';

describe('Collection minting', () => {
const helper = new Helper();

beforeAll(async () => {
await helper.beforeAll();
});

beforeEach(async () => {
await helper.beforeEach();
});

it('Should return credits when nft deposit order does not receive nft', async () => {
mockWalletReturnValue(helper.walletSpy, helper.guardian!, {
network: Network.RMS,
weeks: 25,
type: StakeType.DYNAMIC,
});
const order = await testEnv.wrap(stakeNft)({});
await requestFundsFromFaucet(Network.RMS, order.payload.targetAddress, MIN_IOTA_AMOUNT);

const query = build5Db()
.collection(COL.TRANSACTION)
.where('type', '==', TransactionType.CREDIT)
.where('member', '==', helper.guardian!);
await wait(async () => {
const snap = await query.get<Transaction>();
return (
snap.length === 1 &&
snap[0].payload.walletReference?.confirmed &&
snap[0].payload.amount === MIN_IOTA_AMOUNT
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { build5Db } from '@build-5/database';
import { COL, MIN_IOTA_AMOUNT, Network, Transaction, TransactionType } from '@build-5/interfaces';
import { depositNft } from '../../src/runtime/firebase/nft/index';
import { mockWalletReturnValue, wait } from '../../test/controls/common';
import { testEnv } from '../../test/set-up';
import { requestFundsFromFaucet } from '../faucet';
import { Helper } from './Helper';

describe('Collection minting', () => {
const helper = new Helper();

beforeAll(async () => {
await helper.beforeAll();
});

beforeEach(async () => {
await helper.beforeEach();
});

it('Should return credits when nft deposit order does not receive nft', async () => {
mockWalletReturnValue(helper.walletSpy, helper.guardian!, { network: helper.network });
const order = await testEnv.wrap(depositNft)({});
await requestFundsFromFaucet(Network.RMS, order.payload.targetAddress, MIN_IOTA_AMOUNT);

const query = build5Db()
.collection(COL.TRANSACTION)
.where('type', '==', TransactionType.CREDIT)
.where('member', '==', helper.guardian!);
await wait(async () => {
const snap = await query.get<Transaction>();
return (
snap.length === 1 &&
snap[0].payload.walletReference?.confirmed &&
snap[0].payload.amount === MIN_IOTA_AMOUNT
);
});
});
});

0 comments on commit 5c63977

Please sign in to comment.