fix(staking):make unit test great again

test
neeboo 5 years ago
parent b4e6a94e72
commit 244230cd46
  1. 39
      examples/staking_test.js
  2. 42
      packages/harmony-staking/test/testSign.test.ts

@ -1,14 +1,13 @@
const { Harmony } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');
const {
StakingTransaction,
CreateValidator,
Delegate,
Undelegate,
CollectRewards,
} = require('@harmony-js/staking');
const { StakingFactory } = require('@harmony-js/staking');
const createMsg = CreateValidator({
const harmony = new Harmony('http://localhost:9500', {
chainId: ChainID.HmyLocal,
chainType: ChainType.Harmony,
});
const createMsg = {
validatorAddress: 'one1a0x3d6xpmr6f8wsyaxd9v36pytvp48zckswvv9',
description: {
name: 'Alice',
@ -17,7 +16,7 @@ const createMsg = CreateValidator({
securityContact: 'Bob',
details: "Don't mess with me!!!",
},
commissionRates: {
commissionRate: {
rate: '0.1',
maxRate: '0.9',
maxChangeRate: '0.05',
@ -28,21 +27,21 @@ const createMsg = CreateValidator({
'0xb9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b62247608611',
],
amount: '0x64',
});
};
const stakingTxn = StakingTransaction({
directive: '0x',
stakeMsg: createMsg,
nonce: '0x2',
gasPrice: '0x',
gasLimit: '0x64',
chainId: 0,
from: 'one1a0x3d6xpmr6f8wsyaxd9v36pytvp48zckswvv9',
});
const stakingTxn = harmony.stakings
.createValidator(createMsg)
.setTxParams({
nonce: '0x2',
gasPrice: '0x',
gasLimit: '0x64',
chainId: 0,
})
.build();
stakingTxn
.sendTransaction()
.then((stakingTxn, res) => {
.then(([stakingTxn, res]) => {
console.log(res);
})
.catch((err) => {

@ -171,27 +171,27 @@ describe('test sign staking transaction', () => {
expect(signed[1]).toEqual(testTx.encoded);
});
// it('should test sign delegate staking transaction', () => {
// const testTx: any = testTransactions[2];
// const address = getAddressFromPrivateKey(testTx.privateKey);
// expect(isValidAddress(address)).toEqual(true);
// const stakeMsg: Delegate = new Delegate(
// testTx.delegatorAddress,
// testTx.validatorAddress,
// testTx.amount,
// );
// const stakingTx: StakingTransaction = new StakingTransaction(
// Directive.DirectiveDelegate,
// stakeMsg,
// testTx.nonce,
// testTx.gasPrice,
// testTx.gasLimit,
// testTx.ChainID,
// );
// const signed = stakingTx.rlpSign(testTx.privateKey);
// expect(signed[1]).toEqual(testTx.encoded);
// });
it('should test sign delegate staking transaction', () => {
const testTx: any = testTransactions[2];
const address = getAddressFromPrivateKey(testTx.privateKey);
expect(isValidAddress(address)).toEqual(true);
const stakeMsg: Delegate = new Delegate(
testTx.delegatorAddress,
testTx.validatorAddress,
testTx.amount,
);
const stakingTx: StakingTransaction = new StakingTransaction(
Directive.DirectiveDelegate,
stakeMsg,
testTx.nonce,
testTx.gasPrice,
testTx.gasLimit,
testTx.chainID,
);
const signed = stakingTx.rlpSign(testTx.privateKey);
expect(signed[1]).toEqual(testTx.encoded);
});
it('should test sign delegate staking transaction using factory', () => {
const testTx: any = testTransactions[2];

Loading…
Cancel
Save