Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract endpoint #188

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<!-- | Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-97.98%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.3%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-98%25-brightgreen.svg?style=flat) | -->
| ![Statements](https://img.shields.io/badge/statements-97.88%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.1%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-97.89%25-brightgreen.svg?style=flat) | -->

## 1. Introduction

Expand Down
408 changes: 204 additions & 204 deletions jest-report.xml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions jest.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
// ],

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['text', 'json-summary'],
coverageReporters: ['text', 'json-summary', 'html'],
// coverageReporters: [
// "json",
// "text",
Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = {

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'^randombytes$': '<rootDir>/node_modules/randombytes/index.js',
'^randombytes$': '<rootDir>/node_modules/randombytes/index.js'
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down Expand Up @@ -202,8 +202,8 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.js?$': 'babel-jest',
},
'^.+\\.js?$': 'babel-jest'
}

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
Expand Down
12 changes: 6 additions & 6 deletions jest.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
'!**/examples/**',
'!**/dist/**',
'!**/script/**',
'!**/build/**',
'!**/build/**'
],

// An array of regexp pattern strings used to skip coverage collection
Expand All @@ -46,7 +46,7 @@ module.exports = {
// ],

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['text', 'json-summary'],
coverageReporters: ['text', 'json-summary', 'html'],
// coverageReporters: [
// "json",
// "text",
Expand Down Expand Up @@ -90,7 +90,7 @@ module.exports = {

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'^scryptsy$': path.resolve('src/scrypt-polyfill.js'),
'^scryptsy$': path.resolve('src/scrypt-polyfill.js')
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down Expand Up @@ -156,7 +156,7 @@ module.exports = {
testMatch: [
'**/test/unit/**/?(*.)+(test).[jt]s?(x)',
'**/test/unit/util/httpProvider.node-test.js',
'**/test/unit/util/httpProvider.fetch.node-test.js',
'**/test/unit/util/httpProvider.fetch.node-test.js'
],
testTimeout: 20000,

Expand All @@ -182,8 +182,8 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.js?$': 'babel-jest',
},
'^.+\\.js?$': 'babel-jest'
}

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
Expand Down
11 changes: 6 additions & 5 deletions test/unit/chain/chainMethod.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ChainMethod from '../../../src/chain/chainMethod';
import { inputAddressFormatter, outputFileDescriptorSetFormatter } from '../../../src/util/formatters';
import HttpProvider from '../../../src/util/httpProvider';
import RequestManager from '../../../src/util/requestManage';
import { tdvwEndPoint } from '../constant';

describe('chainMethod should work', () => {
test('test format input params with no inputFormatter', () => {
Expand Down Expand Up @@ -128,11 +129,11 @@ describe('chainMethod should work', () => {
name: 'getChainStatus',
call: 'blockChain/chainStatus'
});
const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io');
const httpProvider = new HttpProvider(tdvwEndPoint);
const manager = new RequestManager(httpProvider);
chainMethod.setRequestManager(manager);
const result = chainMethod.run({ sync: true });
expect(result.ChainId).toEqual('AELF');
expect(result.ChainId).toEqual('tDVW');
});
test('test fn argument when async', async () => {
const chainMethod = new ChainMethod({
Expand All @@ -141,12 +142,12 @@ describe('chainMethod should work', () => {
method: 'GET',
params: []
});
const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io');
const httpProvider = new HttpProvider(tdvwEndPoint);
const manager = new RequestManager(httpProvider);
chainMethod.setRequestManager(manager);
const fn = jest.fn();
const result = await chainMethod.run(fn);
expect(result.ChainId).toEqual('AELF');
expect(result.ChainId).toEqual('tDVW');
expect(fn).toHaveBeenCalled();
expect(fn).toHaveBeenCalledWith(null, result);
});
Expand All @@ -157,7 +158,7 @@ describe('chainMethod should work', () => {
method: 'GET',
params: ['transactionId']
});
const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io');
const httpProvider = new HttpProvider(tdvwEndPoint);
const manager = new RequestManager(httpProvider);
chainMethod.setRequestManager(manager);
// mock
Expand Down
2 changes: 2 additions & 0 deletions test/unit/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const aelfEndPoint = 'https://aelf-test-node.aelf.io';
export const tdvwEndPoint = 'https://tdvw-test-node.aelf.io';
60 changes: 26 additions & 34 deletions test/unit/contract/index.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ContractFactory from '../../../src/contract/index';
const stageEndpoint = 'https://tdvw-test-node.aelf.io';
import AElf from '../../../src/index';
import { tdvwEndPoint } from '../constant';
describe('contract factory', () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const aelf = new AElf(new AElf.providers.HttpProvider(tdvwEndPoint));
const chain = aelf.chain;
const address = 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW';
const fds = chain.getContractFileDescriptorSet(address, {
sync: true,
sync: true
});
const factory = new ContractFactory(chain, fds, AElf.wallet);
test('constrcutor', () => {
Expand Down Expand Up @@ -34,8 +34,8 @@ describe('contract factory', () => {
Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW',
Name: '.aelf.Hash',
Indexed: null,
NonIndexed: 'CgNFTEYQoI/hGQ==',
},
NonIndexed: 'CgNFTEYQoI/hGQ=='
}
];
const contractInstance = factory.at(address);
const result = contractInstance.deserializeLog(Logs, '.aelf.Hash');
Expand All @@ -52,29 +52,23 @@ describe('contract factory', () => {
'EiIKIAR/b9iJa/+kT2+h9XAdQE0UX9wFZogfPtn9YvtlCnB2',
'GiIKICeR6ZKlfyjnWhHxOvLArsiw6zXS8EjULrqJAckuA3jc',
'IghUcmFuc2Zlcg==',
'MiIKICWmXUMWhKDuXFdYz8/uF7ze4kC5r3i7boxM5Dj+RE4G',
'MiIKICWmXUMWhKDuXFdYz8/uF7ze4kC5r3i7boxM5Dj+RE4G'
],
NonIndexed:
'KjAKIgogIKCTibOwFJNFp0zUNEXymkyazYKz8LLwLqOZxEqKRF0SA09NSRiA0NvD9AI=',
},
NonIndexed: 'KjAKIgogIKCTibOwFJNFp0zUNEXymkyazYKz8LLwLqOZxEqKRF0SA09NSRiA0NvD9AI='
}
];
const contractInstance = factory.at(
'238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb'
);
const result = contractInstance.deserializeLog(
Logs,
'VirtualTransactionCreated'
);
expect(result).toEqual(
[{
"from": "2ytdtA2PDX7VLYWkqf36MQQ8wUtcXWRdpovX7Wxy8tJZXumaY",
"methodName": "Transfer",
"params": "CiIKICCgk4mzsBSTRadM1DRF8ppMms2Cs/Cy8C6jmcRKikRdEgNPTUkYgNDbw/QC",
"signatory": "HaiUnezHpBieiVZNuyQV4uLFspYDGxsEwt8wSFYqGSpXY3CzJ",
"to": "JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE",
"virtualHash": "0f09d38a4b246347978cb6296b81262a5d5e3b49d85a2bad2451b91c7dc362d8",
}]
);
const contractInstance = factory.at('238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb');
const result = contractInstance.deserializeLog(Logs, 'VirtualTransactionCreated');
expect(result).toEqual([
{
from: '2ytdtA2PDX7VLYWkqf36MQQ8wUtcXWRdpovX7Wxy8tJZXumaY',
methodName: 'Transfer',
params: 'CiIKICCgk4mzsBSTRadM1DRF8ppMms2Cs/Cy8C6jmcRKikRdEgNPTUkYgNDbw/QC',
signatory: 'HaiUnezHpBieiVZNuyQV4uLFspYDGxsEwt8wSFYqGSpXY3CzJ',
to: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE',
virtualHash: '0f09d38a4b246347978cb6296b81262a5d5e3b49d85a2bad2451b91c7dc362d8'
}
]);
expect(contractInstance.deserializeLog()).toEqual([]);
});
test('test deserialize log with normal contract which has a method called VirtualTransactionCreated', () => {
Expand All @@ -83,8 +77,8 @@ describe('contract factory', () => {
Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW',
Name: 'VirtualTransactionCreated',
Indexed: null,
NonIndexed: 'CgNFTEYQoI/hGQ==',
},
NonIndexed: 'CgNFTEYQoI/hGQ=='
}
];
const contractInstance = factory.at(address);
expect(() => contractInstance.deserializeLog(Logs, 'VirtualTransactionCreated')).toThrow();
Expand All @@ -99,16 +93,14 @@ describe('contract factory', () => {
{
Indexed: [
'CiIKIPoq3y6L7T71F5BynCBXISeMFKrCt4QayljkLE4U8St4',
'EiIKIKt0P1P3+jKuU4Y5rSGOfzleHFw0YXn5eNM88jWfUWYR',
'EiIKIKt0P1P3+jKuU4Y5rSGOfzleHFw0YXn5eNM88jWfUWYR'
],
Name: '.aelf.Hash',
Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW',
},
Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW'
}
];
const contractInstance = factory.at(address);
const result = contractInstance.deserializeLog(Logs, '.aelf.Hash');
expect(result).toEqual([
'0a20fa2adf2e8bed3ef51790729c205721278c14aac2b7841aca58e42c4e14f12b78',
]);
expect(result).toEqual(['0a20fa2adf2e8bed3ef51790729c205721278c14aac2b7841aca58e42c4e14f12b78']);
});
});
12 changes: 5 additions & 7 deletions test/unit/index.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import AElf from '../../src/index';
const stageEndpoint = 'https://tdvw-test-node.aelf.io';
import { aelfEndPoint, tdvwEndPoint } from './constant';
describe('test AElf', () => {
test('test AElf is connected', () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const aelf = new AElf(new AElf.providers.HttpProvider(tdvwEndPoint));
const result = aelf.isConnected();
expect(result).toBeTruthy();
});
test('test AElf set provider', () => {
const aelf = new AElf(
new AElf.providers.HttpProvider('https://aelf-public-node.aelf.io')
);
aelf.setProvider(new AElf.providers.HttpProvider(stageEndpoint));
expect(aelf.currentProvider.host).toEqual(stageEndpoint);
const aelf = new AElf(new AElf.providers.HttpProvider(aelfEndPoint));
aelf.setProvider(new AElf.providers.HttpProvider(tdvwEndPoint));
expect(aelf.currentProvider.host).toEqual(tdvwEndPoint);
});
});
Loading
Loading