Skip to content

Commit af61bab

Browse files
authored
Fix test (#51)
1 parent f8142c2 commit af61bab

File tree

9 files changed

+68
-77
lines changed

9 files changed

+68
-77
lines changed

src/client/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const UserKeystoreClient = (axiosInstance: AxiosInstance) => ({
2727
fetchList: (userIDs: string[]) => axiosInstance.post<unknown, UserResponse[]>(`/users/fetch`, userIDs),
2828

2929
// Create a network user, can be created by bot only with no permission
30-
createBareUser: (fullName: string, sessionSecret: string) => axiosInstance.post<UserResponse>('/users', { full_name: fullName, session_secret: sessionSecret }),
30+
createBareUser: (fullName: string, sessionSecret: string) => axiosInstance.post<unknown, UserResponse>('/users', { full_name: fullName, session_secret: sessionSecret }),
3131

3232
// Modify current user's personal name and avatar
3333
update: (fullName: string, avatarBase64: string) => axiosInstance.post<unknown, UserResponse>(`/me`, { full_name: fullName, avatar_base64: avatarBase64 }),

test/address.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { client } from './common';
1+
import { client, keystore } from './common';
22

33
describe('address', () => {
44
const asset_id = '43d61dcd-e413-450d-80b8-101d5e903357';
55
const destination = '0xF2e6D6BB9E6D31B873bC23649A25A76f8852e3f5';
66
let tmpAddressID = '';
77

88
it('create address if not exsits', async () => {
9-
const receive = await client.createAddress({ asset_id, destination, label: 'test' }, '12345');
9+
const receive = await client.address.create(keystore.pin, { asset_id, destination, label: 'test' });
1010
console.log(receive);
11-
const res = await client.readAddress(receive.address_id);
11+
const res = await client.address.fetch(receive.address_id);
1212
expect(res.address_id).toEqual(receive.address_id);
1313
tmpAddressID = receive.address_id;
1414
});
1515
it('read addresses', async () => {
16-
const list = await client.readAddresses(asset_id);
16+
const list = await client.address.fetchList(asset_id);
1717
const isHave = list.some(item => item.address_id === tmpAddressID);
1818
expect(isHave).toBeTruthy();
1919
});
2020

2121
it('delete address', async () => {
22-
const res = await client.readAddress(tmpAddressID);
22+
const res = await client.address.fetch(tmpAddressID);
2323
expect(res.address_id).toEqual(tmpAddressID);
24-
const t = await client.deleteAddress(tmpAddressID);
24+
const t = await client.address.delete(keystore.pin, tmpAddressID);
2525
expect(t).toBeUndefined();
2626
});
2727
});

test/common.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
import { Client } from '../src';
2-
import fs from 'fs';
3-
const keystore = JSON.parse(fs.readFileSync(__dirname + '/../config.json', 'utf8'));
4-
const client = new Client(keystore);
1+
import { MixinApi } from '../src';
2+
import keystore from './keystore';
53

6-
export { client };
4+
const config = {
5+
requestConfig: {
6+
responseCallback: (err: any) => {
7+
console.log(err);
8+
}
9+
},
10+
keystore
11+
};
12+
const client = MixinApi(config);
13+
14+
export {
15+
client ,
16+
keystore
17+
};
File renamed without changes.

test/mixin/user.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import User from '../../src/client/user';
22
import Pin from '../../src/client/pin';
3-
import keystore from './keystore';
3+
import keystore from '../keystore';
44

55
describe('Tests for users', () => {
66
const user = User({ keystore });

test/mixin/utils.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// @ts-ignore
12
import forge from 'node-forge';
3+
import { v4 as uuid } from 'uuid';
24
import { signAuthenticationToken } from '../../src/client/utils/auth';
35
import { base64RawURLEncode, base64RawURLDecode } from '../../src/client/utils/base64';
46
import { hashMembers, uniqueConversationID } from '../../src/client/utils/uniq';
57
import { sharedEd25519Key, signEd25519PIN } from '../../src/client/utils/pin';
6-
import keystore from './keystore';
8+
import keystore from '../keystore';
79

810
describe('Tests for utils', () => {
911
test('base64 encode & decode should be url safe', () => {
@@ -74,8 +76,7 @@ describe('Tests for utils', () => {
7476
});
7577

7678
test('tests for auth', () => {
77-
expect(signAuthenticationToken('GET', '/me', '', undefined)).toBe('');
78-
expect(signAuthenticationToken('GET', '/me', '', keystore)).not.toBe('');
79-
expect(signAuthenticationToken('POST', '/me', {foo: 'bar'}, keystore)).not.toBe('');
79+
expect(signAuthenticationToken('GET', '/me', '', uuid(), keystore)).not.toBe('');
80+
expect(signAuthenticationToken('POST', '/me', {foo: 'bar'}, uuid(), keystore)).not.toBe('');
8081
});
8182
});

test/mvm/registry.test.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
import Registry, { Blank, MVMTestnet } from '../../src/mvm/registry';
1+
import Registry from '../../src/mvm/registry';
2+
import { BlankAddress, MVMTestnet } from '../../src';
23

34
describe('Tests for registry', () => {
45
const registry = new Registry({ address: MVMTestnet.Registry.Address, uri: MVMTestnet.RPCUri});
56

67
test('Test for fetch mvm address of mixin asset', async () => {
7-
const address = await registry.fetchAssetAddress('965e5c6e-434c-3fa9-b780-c50f43cd955c');
8-
expect(address).toMatch('0x155bDfAb24f07630C27a3F31634B33F94eC4A634');
8+
const address = await registry.fetchAssetContract('965e5c6e-434c-3fa9-b780-c50f43cd955c');
9+
expect(address).toMatch('0x9896c802e143A59A98c0C26bBa6d11C1AAF4A023');
910
});
1011

1112
test('Test for fetch invalid mvm address of mixin asset', async () => {
12-
const address = await registry.fetchAssetAddress('e9e5b807-fa8b-455a-8dfa-b189d28310ff');
13-
expect(address).toMatch(Blank);
13+
const address = await registry.fetchAssetContract('e9e5b807-fa8b-455a-8dfa-b189d28310ff');
14+
expect(address).toMatch(BlankAddress);
1415
});
1516

16-
test('Test for fetch mvm address of mixin user', async () => {
17-
const address = await registry.fetchUsersAddress(['e9e5b807-fa8b-455a-8dfa-b189d28310ff'], 1);
18-
expect(address).toMatch('0x8a9f2B6492A3E24B1D2b92ad29E80549Be6B21Cc');
19-
});
20-
21-
test('Test for fetch mvm address of a mixin user without threshold', async () => {
22-
const address = await registry.fetchUserAddress('e9e5b807-fa8b-455a-8dfa-b189d28310ff');
23-
expect(address).toMatch('0x8a9f2B6492A3E24B1D2b92ad29E80549Be6B21Cc');
17+
test('Test for fetch invalid mvm address of mixin user', async () => {
18+
const address = await registry.fetchUsersContract(['965e5c6e-434c-3fa9-b780-c50f43cd955c'], 1);
19+
expect(address).toMatch(BlankAddress);
2420
});
2521

26-
test('Test for fetch invalid mvm address of mixin user', async () => {
27-
const address = await registry.fetchUsersAddress(['965e5c6e-434c-3fa9-b780-c50f43cd955c'], 1);
28-
expect(address).toMatch(Blank);
22+
test('Test for fetch mvm address of mixin user', async () => {
23+
const address = await registry.fetchUsersContract(['e9e5b807-fa8b-455a-8dfa-b189d28310ff'], 1);
24+
expect(address).toMatch('0xc09516323c601006DbaDb330778fADCE08593252');
2925
});
3026

31-
test('Test for default registry', async () => {
32-
const defaultRegistry = new Registry({});
33-
const address = await defaultRegistry.fetchAssetAddress('965e5c6e-434c-3fa9-b780-c50f43cd955c');
34-
expect(address).toMatch('0x155bDfAb24f07630C27a3F31634B33F94eC4A634');
27+
test('Test for fetch mvm address of a mixin user without threshold', async () => {
28+
const address = await registry.fetchUserContract('e9e5b807-fa8b-455a-8dfa-b189d28310ff');
29+
expect(address).toMatch('0xc09516323c601006DbaDb330778fADCE08593252');
3530
});
3631
});

test/nft.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
import { client } from './common';
21
import { v4 as uuid } from 'uuid';
2+
import { client } from './common';
3+
import { MintAssetID, MintMinimumCost, GroupMembers, GroupThreshold } from '../src/client/collectible';
4+
import { buildMintCollectibleMemo } from '../src';
35

46
describe('address', () => {
57
it('create nft', async () => {
68
const id = uuid();
7-
8-
const tr = client.newMintCollectibleTransferInput({
9+
const tr = {
10+
asset_id: MintAssetID,
11+
amount: MintMinimumCost,
912
trace_id: id,
10-
collection_id: id,
11-
token_id: id,
12-
content: 'test',
13-
});
13+
memo: buildMintCollectibleMemo(id, id, 'test'),
14+
opponent_multisig: {
15+
receivers: GroupMembers,
16+
threshold: GroupThreshold
17+
}
18+
};
1419

15-
const payment = await client.verifyPayment(tr);
20+
const payment = await client.payment.request(tr);
1621
console.log('mint collectibles', id, `mixin://codes/${payment.code_id}`);
1722
expect(payment.trace_id).toEqual(id);
1823
});

test/user.test.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,28 @@
1-
import { client } from './common';
1+
import { client, keystore } from './common';
22

33
describe('user', () => {
4-
it('userMe', async () => {
5-
const user = await client.userMe();
6-
expect(user.user_id).toEqual(client.keystore.client_id);
4+
it('profile', async () => {
5+
const user = await client.user.profile();
6+
expect(user.user_id).toEqual(keystore.user_id);
77
});
88

9-
it('readUser', async () => {
10-
const user = await client.readUser('30265');
11-
expect(user.identity_number).toEqual('30265');
9+
it('fetch', async () => {
10+
const user = await client.user.fetch(keystore.user_id);
11+
expect(user.user_id).toEqual(keystore.user_id);
1212
});
1313

1414
it('readBlockUsers', async () => {
15-
const user = await client.readBlockUsers();
15+
const user = await client.user.blockings();
1616
expect(Array.isArray(user)).toBeTruthy();
1717
});
1818

19-
it('readUsers', async () => {
20-
const users = await client.readUsers(['e8e8cd79-cd40-4796-8c54-3a13cfe50115']);
19+
it('fetchList', async () => {
20+
const users = await client.user.fetchList(['e8e8cd79-cd40-4796-8c54-3a13cfe50115']);
2121
expect(users[0].identity_number).toEqual('30265');
2222
});
2323

24-
it('searchUser', async () => {
25-
// const user1 = await client.searchUser("+8613801380138")
26-
// expect(user1.identity_number).toEqual("7000")
27-
const user2 = await client.searchUser('30265');
28-
expect(user2.identity_number).toEqual('30265');
29-
});
30-
3124
it('readFriends', async () => {
32-
const user = await client.readFriends();
25+
const user = await client.user.friends();
3326
expect(Array.isArray(user)).toBeTruthy();
3427
});
35-
36-
it('createUser', async () => {
37-
const user = await client.createUser('测试...');
38-
expect(user.full_name).toEqual('测试...');
39-
});
40-
41-
it('modifyProfile', async () => {
42-
let user = await client.userMe();
43-
let name = user.full_name;
44-
user = await client.modifyProfile('测试...');
45-
expect(user.full_name).toEqual('测试...');
46-
user = await client.modifyProfile(name);
47-
expect(user.full_name).toEqual(name);
48-
});
4928
});

0 commit comments

Comments
 (0)