Skip to content

Commit

Permalink
testcase: update staking tx & query
Browse files Browse the repository at this point in the history
  • Loading branch information
fly33499 committed Oct 13, 2021
1 parent 05b7aa1 commit a00f0fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
26 changes: 13 additions & 13 deletions test/12.staking_tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ describe('[12. Staking Tx Test]', () => {

it('delegate OK', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
const wallet = await firma.Wallet.fromMnemonic(bobMnemonic);
const validatorList = await firma.Staking.getValidatorList();
const validatorAddress = validatorList[0].operator_address;

const amountFCT = 60;

var result = await firma.Staking.delegate(wallet, validatorAddress, amountFCT);
Expand All @@ -22,11 +22,11 @@ describe('[12. Staking Tx Test]', () => {

it('undelegate OK', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
const wallet = await firma.Wallet.fromMnemonic(bobMnemonic);
const validatorList = await firma.Staking.getValidatorList();
const validatorAddress = validatorList[0].operator_address;

const amount = 1;
const amount = 5;

// if there's 7 more list on undelegatelist, occur error below
// too many unbonding delegation entries for (delegator, validator) tuple
Expand All @@ -35,7 +35,7 @@ describe('[12. Staking Tx Test]', () => {
expect(result.code).to.equal(0);
});

it.skip('redelegate OK', async () => {
it('redelegate OK', async () => {

//INFO: need two validators but starport serve support only one validator.

Expand All @@ -46,7 +46,7 @@ describe('[12. Staking Tx Test]', () => {
const srcValidatorAddress = validatorList[0].operator_address;
const dstValidatorAddress = validatorList[1].operator_address;

const amount = 1;
const amount = 10;

let result = await firma.Staking.delegate(wallet, srcValidatorAddress, amount);
expect(result.code).to.equal(0);
Expand All @@ -55,24 +55,24 @@ describe('[12. Staking Tx Test]', () => {
let result1 = await firma.Staking.redelegate(wallet, srcValidatorAddress, dstValidatorAddress, amount,
{ gas: 300000, fee: 3000 });

expect(result1.code).to.equal(0);
expect(result1.code).to.equal(0);
});

// new case added. if succeed, the dapp needs to prevent zero amount input from users.
it('staking send Fail - send zero money', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);

const validatorList = await firma.Staking.getValidatorList();
const validatorAddress = validatorList[0].operator_address;

const amount = 0;

try{
try {
var result = await firma.Staking.delegate(wallet, validatorAddress, amount);
}
catch(error){
catch (error) {

}

//expect(result.code).to.equal(5);
Expand All @@ -82,7 +82,7 @@ describe('[12. Staking Tx Test]', () => {
it('staking send Fail - send lots of money', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);

const validatorList = await firma.Staking.getValidatorList();
const validatorAddress = validatorList[0].operator_address;

Expand All @@ -98,7 +98,7 @@ describe('[12. Staking Tx Test]', () => {
it.skip('editValidator OK', async () => {

const wallet = await firma.Wallet.fromMnemonic(validatorMnemonic);

const validatorList = await firma.Staking.getValidatorList();
const validatorAddress = validatorList[0].operator_address;

Expand Down
60 changes: 31 additions & 29 deletions test/13.staking_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,72 @@ describe('[13. Staking Query Test]', () => {

const firma = new FirmaSDK(TestChainConfig);

it('get validator list', async () => {
it('1.get total validator list', async () => {

var result = await firma.Staking.getValidatorList();
expect(result.length).to.above(0);
//console.log(result);
})

//console.log(result[0].grantee);
//console.log("total: " + result.length);
//console.log("commission_rates.max_rate:" + result[0].commission.commission_rates.max_rate);
it('2.get validator data', async () => {

var validatorList = await firma.Staking.getValidatorList();
var result = await firma.Staking.getValidator(validatorList[0].operator_address);
//console.log(result);
})

it('get pool', async () => {
it('3.get getDelegationListFromValidator', async () => {

var result = await firma.Staking.getPool();
//console.log(result.bonded_tokens);
//console.log(result.not_bonded_tokens);
var validatorList = await firma.Staking.getValidatorList();
var result = await firma.Staking.getDelegationListFromValidator(validatorList[1].operator_address);
//console.log(result);
})

it('get getParams', async () => {
it('4.get getUndelegationListFromValidator', async () => {

var validatorList = await firma.Staking.getValidatorList();
var result = await firma.Staking.getUndelegationListFromValidator(validatorList[0].operator_address);

var result = await firma.Staking.getParams();
//console.log(result);
})

// [TODO: need to implement]
// get delegation list based validator side
// not give total delegations, but give each user amount list.
it.skip('get getTotalDelegationFromValidator', async () => {
// param side
it('5.get staking total pool', async () => {

// [CHECK]
// I'm confusing of modify return type of cosmos sdk rest api
// Too complicated. I'm still thinking about it.
var result = await firma.Staking.getPool();

//const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
//var result = await firma.Staking.getTotalDelegationInfo(await wallet.getAddress());
// bonded_token, not_bonded_tokens
//console.log(result);
})


it('6.get getParams', async () => {

var result = await firma.Staking.getParams();
//console.log(result);
})


// Receive a list of supplies delegated by the user.
it('get getTotalDelegationInfo', async () => {
// user side
it('7.get userside getTotalDelegationInfo', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
var result = await firma.Staking.getTotalDelegationInfo(await wallet.getAddress());

//console.log(result);
})

it('get getTotalRedelegationInfo', async () => {
it('8.get userside getTotalRedelegationInfo', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
var result = await firma.Staking.getTotalRedelegationInfo(await wallet.getAddress());

//console.log(result);
//console.log(result[0].entries[0].redelegation_entry.creation_height);
//console.log(result[0].entries[0]);
})

it('get getTotalUnbondingInfo', async () => {
it('9.get userside getTotalUndelegateInfo', async () => {

const wallet = await firma.Wallet.fromMnemonic(aliceMnemonic);
var result = await firma.Staking.getTotalUnbondingInfo(await wallet.getAddress());
var result = await firma.Staking.getTotalUndelegateInfo(await wallet.getAddress());

//console.log(result);
//console.log(result[0].entries[0]);
})
});

0 comments on commit a00f0fd

Please sign in to comment.