Skip to content

Commit

Permalink
Add test for createAddressId()
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Nov 22, 2022
1 parent f33dfef commit d4f323f
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions integration-tests/src/test/register-address.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { ApiPromise, Keyring, WsProvider, KeyringPair, Wallet, POINT_01_CTC } from 'creditcoin-js';
import { Blockchain, Keyring, KeyringPair, Wallet, POINT_01_CTC, creditcoinApi } from 'creditcoin-js';
import { createAddressId } from 'creditcoin-js/lib/extrinsics/register-address';
import { createCreditcoinBlockchain } from 'creditcoin-js/lib/transforms';
import { checkAddress, testData } from 'creditcoin-js/lib/testUtils';
import { CreditcoinApi } from 'creditcoin-js/lib/types';
import { signAccountId } from 'creditcoin-js/lib/utils';
import { extractFee } from '../utils';

describe('RegisterAddress', () => {
let api: ApiPromise;
let ccApi: CreditcoinApi;
let alice: KeyringPair;

beforeAll(async () => {
api = await ApiPromise.create({
provider: new WsProvider((global as any).CREDITCOIN_API_URL),
});
ccApi = await creditcoinApi((global as any).CREDITCOIN_API_URL);
alice = new Keyring({ type: 'sr25519' }).addFromUri('//Alice');
});

afterAll(async () => await api.disconnect());
afterAll(async () => await ccApi.api.disconnect());

it('fee is min 0.01 CTC', async (): Promise<void> => {
const { api } = ccApi;

return new Promise((resolve, reject) => {
const wallet = Wallet.createRandom();
const unsubscribe = api.tx.creditcoin
Expand All @@ -33,4 +36,33 @@ describe('RegisterAddress', () => {
expect(fee).toBeGreaterThanOrEqual(POINT_01_CTC);
});
});

it('createAddressId works as expected', async (): Promise<void> => {
const { blockchain } = testData(
(global as any).CREDITCOIN_ETHEREUM_CHAIN as Blockchain,
(global as any).CREDITCOIN_CREATE_WALLET,
);

const {
api,
extrinsics: { registerAddress },
} = ccApi;

const lender = alice;
const lenderWallet = Wallet.createRandom();
const lenderRegAddr = await registerAddress(
lenderWallet.address,
blockchain,
signAccountId(api, lenderWallet, lender.address),
lender,
);

// manually constructed address is the same as returned by Creditcoin
const addressId = createAddressId(blockchain, lenderWallet.address);
expect(addressId).toBe(lenderRegAddr.itemId);

// manually constructed address should be reported as registered
const result = await checkAddress(ccApi, addressId);
expect(result).toBeDefined();
});
});

0 comments on commit d4f323f

Please sign in to comment.