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 11703d6 commit ce5b590
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions integration-tests/src/test/register-address.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { ApiPromise, Keyring, WsProvider, KeyringPair, Wallet, POINT_01_CTC } from 'creditcoin-js';
import { Keyring, KeyringPair, Wallet, POINT_01_CTC, creditcoinApi } from 'creditcoin-js';
import { createCreditcoinBlockchain } from 'creditcoin-js/lib/transforms';
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 +34,27 @@ describe('RegisterAddress', () => {
expect(fee).toBeGreaterThanOrEqual(POINT_01_CTC);
});
});

it('createAddressId works as expected', async (): Promise<void> => {
const {
extrinsics: { registerAddress },
} = ccApi;

const lender = alice;
const lenderWallet = Wallet.createRandom();
const lenderRegAddr = await registerAddress(
lenderWallet.address,
blockchain,
signAccountId(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 ce5b590

Please sign in to comment.