Skip to content

Commit

Permalink
feat: fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Jun 24, 2024
2 parents 4148544 + 5a61939 commit 3cb69fe
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 10,194 deletions.
6 changes: 3 additions & 3 deletions jest.browser.config.js
Original file line number Diff line number Diff line change
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 @@ -193,8 +193,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
57 changes: 30 additions & 27 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* @file AElf-sdk constants
* @author atom-yang
*/
import { inputAddressFormatter, outputFileDescriptorSetFormatter } from '../util/formatters';
import {
inputAddressFormatter,
outputFileDescriptorSetFormatter,
} from '../util/formatters';

/**
* unsigned 256 int
Expand All @@ -14,121 +17,121 @@ export const CHAIN_METHODS = {
name: 'getChainStatus',
call: 'blockChain/chainStatus',
method: 'GET',
params: []
params: [],
},
getChainState: {
name: 'getChainState',
call: 'blockChain/blockState',
method: 'GET',
params: ['blockHash']
params: ['blockHash'],
},
getContractFileDescriptorSet: {
name: 'getContractFileDescriptorSet',
call: 'blockChain/contractFileDescriptorSet',
method: 'GET',
params: ['address'],
inputFormatter: [inputAddressFormatter],
outputFormatter: outputFileDescriptorSetFormatter
outputFormatter: outputFileDescriptorSetFormatter,
},
getBlockHeight: {
name: 'getBlockHeight',
call: 'blockChain/blockHeight',
method: 'GET',
params: [],
inputFormatter: []
inputFormatter: [],
},
getBlock: {
name: 'getBlock',
call: 'blockChain/block',
method: 'GET',
params: ['blockHash', 'includeTransactions']
params: ['blockHash', 'includeTransactions'],
},
getBlockByHeight: {
name: 'getBlockByHeight',
call: 'blockChain/blockByHeight',
method: 'GET',
params: ['blockHeight', 'includeTransactions']
params: ['blockHeight', 'includeTransactions'],
},
getTxResult: {
name: 'getTxResult',
call: 'blockChain/transactionResult',
method: 'GET',
params: ['transactionId'],
inputFormatter: []
inputFormatter: [],
},
getTxResults: {
name: 'getTxResults',
call: 'blockChain/transactionResults',
method: 'GET',
params: ['blockHash', 'offset', 'limit']
params: ['blockHash', 'offset', 'limit'],
},
getMerklePathByTxId: {
name: 'getMerklePathByTxId',
call: 'blockChain/merklePathByTransactionId',
method: 'GET',
params: ['transactionId']
params: ['transactionId'],
},
getTransactionPoolStatus: {
name: 'getTransactionPoolStatus',
call: 'blockChain/transactionPoolStatus',
method: 'GET',
params: []
params: [],
},
sendTransaction: {
name: 'sendTransaction',
call: 'blockChain/sendTransaction',
method: 'POST',
params: ['rawTransaction'],
inputFormatter: []
inputFormatter: [],
},
sendTransactions: {
name: 'sendTransactions',
call: 'blockChain/sendTransactions',
method: 'POST',
params: ['rawTransaction'],
inputFormatter: []
inputFormatter: [],
},
calculateTransactionFee: {
name: 'calculateTransactionFee',
call: 'blockChain/calculateTransactionFee',
method: 'POST',
params: ['rawTransaction'],
inputFormatter: []
inputFormatter: [],
},
callReadOnly: {
name: 'callReadOnly',
call: 'blockChain/executeTransaction',
method: 'POST',
params: ['rawTransaction'],
inputFormatter: []
inputFormatter: [],
},
getPeers: {
name: 'getPeers',
call: 'net/peers',
method: 'GET',
params: ['withMetrics']
params: ['withMetrics'],
},
addPeer: {
name: 'addPeer',
call: 'net/peer',
method: 'POST',
params: ['address'],
inputFormatter: []
inputFormatter: [],
},
removePeer: {
name: 'removePeer',
call: 'net/peer',
method: 'DELETE',
params: ['address'],
inputFormatter: []
inputFormatter: [],
},
networkInfo: {
name: 'networkInfo',
call: 'net/networkInfo',
method: 'GET',
params: [],
inputFormatter: []
}
inputFormatter: [],
},
};

/**
Expand Down Expand Up @@ -161,7 +164,7 @@ export const UNIT_MAP = {
grand: '1000000000000000000000',
mether: '1000000000000000000000000',
gether: '1000000000000000000000000000',
tether: '1000000000000000000000000000000'
tether: '1000000000000000000000000000000',
};

export const TO_STRING_UTF8_ENCODING = 'utf8';
Expand All @@ -174,24 +177,24 @@ export const CONGIG = {
contractZeroAddress: 'AELF',
contractZeroAbi: 'AELF',
contractZero: 'AELF',
defaultAccount: '0x04bb9c6c297ea90b1bc3e6af2c87d416583e'
defaultAccount: '0x04bb9c6c297ea90b1bc3e6af2c87d416583e',
};

export const KEY_STORE_ERRORS = {
INVALID_PASSWORD: {
error: 200001,
errorMessage: 'Password Error'
errorMessage: 'Password Error',
},
NOT_AELF_KEY_STORE: {
error: 200002,
errorMessage: 'Not a aelf key store'
errorMessage: 'Not a aelf key store',
},
WRONG_VERSION: {
error: 200004,
errorMessage: 'The version is incorrect'
errorMessage: 'The version is incorrect',
},
WRONG_KEY_STORE_VERSION: {
error: 200005,
errorMessage: 'Not a V1 key store'
}
errorMessage: 'Not a V1 key store',
},
};
4 changes: 4 additions & 0 deletions src/contract/contractMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export default class ContractMethod {
return null;
}
let params = transformMapToArray(this._outputType, result);

params = transform(this._outputType, params, INPUT_TRANSFORMERS);

const message = this._outputType.fromObject(params);
return this._outputType.encode(message).finish();
}
Expand All @@ -89,6 +91,8 @@ export default class ContractMethod {
let tx = wallet.signTransaction(rawTx, this._wallet.keyPair);

tx = Transaction.encode(tx).finish();
// jest environment just go into Buffer branch
// we have test in browser example handly
if (tx instanceof Buffer) {
return tx.toString('hex');
}
Expand Down
43 changes: 43 additions & 0 deletions test/e2e/wallet.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AElf from '../../src/index';
let aelf = null;
<<<<<<< HEAD
const address = "SbWhnq3XU8yeiUTYJmZBSgt7ekgszRXHxh8qNqkFj9g6d3bWh";
const mnemonic = 'orange learn result add snack curtain double state expose bless also clarify';
const privateKey =
Expand All @@ -8,6 +9,17 @@ describe('test wallet', () => {
test('create instance',() => {
aelf = new AElf(
new AElf.providers.HttpProvider("https://aelf-test-node.aelf.io")
=======
const address = 'YxE2zSWev5AGuBNtStW5Mdw8HyVtcZ8X5vYmKAx9yZ7dPnRo5';
const mnemonic =
'orange learn result add snack curtain double state expose bless also clarify';
const privateKey =
'a831378a02a765c577de1c2f69800c905f5dd410940eb08e7711fb38c6de18b5';
describe('test wallet', () => {
test('create instance', () => {
aelf = new AElf(
new AElf.providers.HttpProvider('https://explorer-test.aelf.io/chain')
>>>>>>> 5a6193917ab83cb9841e9959e31601d12279acca
);
expect(aelf).toBeDefined();
expect(aelf.isConnected()).toBeTruthy();
Expand All @@ -23,6 +35,7 @@ describe('test wallet', () => {
}, 60000);

test('test create new wallet', () => {
<<<<<<< HEAD
const {
address,
mnemonic,
Expand Down Expand Up @@ -56,6 +69,36 @@ describe('test wallet', () => {
});


test('test check new wallet address', () => {
const { address, mnemonic, privateKey } = AElf.wallet.createNewWallet();
const walletGotByKey1 = AElf.wallet.getWalletByPrivateKey(privateKey);
const walletGotByMn1 = AElf.wallet.getWalletByMnemonic(mnemonic);
expect(walletGotByKey1.address).toEqual(address);
expect(walletGotByMn1.address).toEqual(address);

const walletGotByKey2 = AElf.wallet.getWalletByPrivateKey(privateKey);
const walletGotByMn2 = AElf.wallet.getWalletByMnemonic(mnemonic);
expect(walletGotByKey2.address).toEqual(address);
expect(walletGotByMn2.address).toEqual(address);


const walletGotByKey3 = AElf.wallet.getWalletByPrivateKey(privateKey);
const walletGotByMn3 = AElf.wallet.getWalletByMnemonic(mnemonic);

expect(walletGotByKey3.address).toEqual(address);
expect(walletGotByMn3.address).toEqual(address);

=======
const { address, mnemonic, privateKey } = AElf.wallet.createNewWallet();
const walletGotByKey = AElf.wallet.getWalletByPrivateKey(privateKey);
const walletGotByMn = AElf.wallet.getWalletByMnemonic(mnemonic);
expect(walletGotByKey.address).toEqual(address);
expect(walletGotByMn.privateKey).toEqual(privateKey);
expect(walletGotByMn.address).toEqual(address);
>>>>>>> 5a6193917ab83cb9841e9959e31601d12279acca
});


test('test check new wallet address', () => {
const { address, mnemonic, privateKey } = AElf.wallet.createNewWallet();
const walletGotByKey1 = AElf.wallet.getWalletByPrivateKey(privateKey);
Expand Down
Loading

0 comments on commit 3cb69fe

Please sign in to comment.