Skip to content

Commit

Permalink
fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Dec 17, 2021
1 parent 879bbb7 commit 733075e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
11 changes: 5 additions & 6 deletions src/__tests__/acceptance/currency.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
givenMultipleCurrencyInstances,
setupApplication,
} from '../helpers';
import acala from '../../data-seed/currencies.json';

/* eslint-disable @typescript-eslint/no-invalid-this */
describe('CurrencyApplication', () => {
Expand Down Expand Up @@ -112,16 +111,16 @@ describe('CurrencyApplication', () => {
const currencyInProgress = await givenCurrencyInstance(
currencyRepository,
{
id: 'DOT',
decimal: 10,
id: 'AUSD',
decimal: 13,
image: 'https://apps.acala.network/static/media/AUSD.439bc3f2.png',
native: false,
native: true,
rpcURL: 'wss://acala-mandala.api.onfinality.io/public-ws',
types: acala[0].types,
networkType: 'substrate-test',
},
);

const filter = 'filter=' + JSON.stringify({where: {id: 'DOT'}});
const filter = 'filter=' + JSON.stringify({where: {id: 'AUSD'}});

await client
.get('/currencies')
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/acceptance/transaction-summary.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('TransactionSummaryApplication', function () {
expect(response.body).to.deepEqual({
sent: [
{
currencyId: DefaultCurrencyType.AUSD,
currencyId: 'ROC',
amount:
transactionSentInstance1.amount +
transactionSentInstance2.amount +
Expand All @@ -107,7 +107,7 @@ describe('TransactionSummaryApplication', function () {
],
received: [
{
currencyId: DefaultCurrencyType.AUSD,
currencyId: 'ROC',
amount:
transactionReceivedInstance1.amount +
transactionReceivedInstance2.amount +
Expand All @@ -125,7 +125,7 @@ describe('TransactionSummaryApplication', function () {

expect(response.body).to.containDeep([
{
currencyId: DefaultCurrencyType.AUSD,
currencyId: 'ROC',
amount:
transactionSentInstance1.amount + transactionSentInstance2.amount,
},
Expand All @@ -140,7 +140,7 @@ describe('TransactionSummaryApplication', function () {

expect(response.body).to.containDeep([
{
currencyId: DefaultCurrencyType.AUSD,
currencyId: 'ROC',
amount: transactionSentInstance3.amount,
},
]);
Expand Down
7 changes: 1 addition & 6 deletions src/__tests__/acceptance/user-currency.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ describe('UserCurrencyApplication', function () {

await givenUserCurrencyInstance(userCurrencyRepository, {
userId: user.id,
currencyId: DefaultCurrencyType.MYRIA,
});

await givenUserCurrencyInstance(userCurrencyRepository, {
userId: user.id,
currencyId: DefaultCurrencyType.AUSD,
currencyId: 'ROC',
});

const userCurrency = givenUserCurrency({userId: user.id});
Expand Down
17 changes: 8 additions & 9 deletions src/__tests__/helpers/given-instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
UserSocialMediaRepository,
VoteRepository,
} from '../../repositories';
import acala from '../../data-seed/currencies.json';

/* eslint-disable @typescript-eslint/no-explicit-any */
export function givenUser(user?: Partial<User>) {
Expand Down Expand Up @@ -230,13 +229,13 @@ export async function givenPostInstance(
export function givenCurrency(currency?: Partial<Currency>) {
const data = Object.assign(
{
id: 'AUSD',
id: 'ROC',
decimal: 12,
image: 'https://apps.acala.network/static/media/AUSD.439bc3f2.png',
native: false,
rpcURL: 'wss://acala-mandala.api.onfinality.io/public-ws',
types: acala[0].types,
image: 'https://polkadot.js.org/apps/static/rococo.afea08ac.svg',
native: true,
rpcURL: 'wss://rococo-rpc.polkadot.io',
networkType: 'substrate-test',
exchangeRate: false,
},
currency,
);
Expand All @@ -261,7 +260,7 @@ export async function givenMultipleCurrencyInstances(
image: 'https://apps.acala.network/static/media/AUSD.439bc3f2.png',
native: true,
rpcURL: 'wss://acala-mandala.api.onfinality.io/public-ws',
networkType: 'substrate',
networkType: 'substrate-test',
}),
]);
}
Expand Down Expand Up @@ -398,7 +397,7 @@ export function givenTransaction(transaction?: Partial<Transaction>) {
amount: 1,
from: '0x06cc7ed22ebd12ccc28fb9c0d14a5c4420a331d89a5fef48b915e8449ee61864',
to: '0x06cc7ed22ebd12ccc28fb9c0d14a5c4420a331d89a5fef48b915e8449ee61865',
currencyId: 'AUSD',
currencyId: 'ROC',
},
transaction,
);
Expand All @@ -417,7 +416,7 @@ export function givenUserCurrency(userCurrency?: Partial<UserCurrency>) {
{
userId:
'0x06cc7ed22ebd12ccc28fb9c0d14a5c4420a331d89a5fef48b915e8449ee61864',
currencyId: 'AUSD',
currencyId: 'ROC',
},
userCurrency,
);
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const config = {
MYRIAD_MNEMONIC: process.env.MYRIAD_FAUCET_MNEMONIC ?? generateSeed(),
MYRIAD_REWARD_AMOUNT: +(process.env.MYRIAD_REWARD_AMOUNT ?? 0),

MYRIAD_OFFICIAL_ACCOUNT: process.env.MYRIAD_OFFICIAL_ACCOUNT_PUBLIC_KEY ?? '',
MYRIAD_OFFICIAL_ACCOUNT:
process.env.MYRIAD_OFFICIAL_ACCOUNT_PUBLIC_KEY ??
'0x06cc7ed22ebd12ccc28fb9c0d14a5c1220a331d89a5fef48b915e8449ee61859',

ESCROW_SECRET_KEY: process.env.ESCROW_SECRET_KEY ?? 's3cr3+<3y',

Expand Down
10 changes: 7 additions & 3 deletions src/services/currency.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
UserSocialMediaRepository,
} from '../repositories';
import {PolkadotJs} from '../utils/polkadotJs-utils';
import acala from '../data-seed/currencies.json';
import {HttpErrors} from '@loopback/rest';
import {BcryptHasher} from './authentication/hash.password.service';
import {NotificationService} from './notification.service';
Expand Down Expand Up @@ -77,14 +76,19 @@ export class CurrencyService {

async defaultAcalaTips(userId: string): Promise<void> {
try {
const {
rpcURL: acalaRpc,
decimal: acalaDecimal,
types,
} = await this.currencyRepository.findById(DefaultCurrencyType.AUSD);

const {polkadotApi, getKeyring} = new PolkadotJs();
const api = await polkadotApi(acala[0].rpcURL, acala[0].types);
const api = await polkadotApi(acalaRpc, types);

const mnemonic = config.MYRIAD_MNEMONIC;
const from = getKeyring().addFromMnemonic(mnemonic);
const to = userId;

const acalaDecimal = 12;
const value = config.ACALA_AUSD_REWARD_AMOUNT * 10 ** acalaDecimal;

const {nonce} = await api.query.system.account(from.address);
Expand Down

0 comments on commit 733075e

Please sign in to comment.