Skip to content

Commit

Permalink
2887 update ai rpc (#2923)
Browse files Browse the repository at this point in the history
* feat: update getDelegates rpc type with adaptive issuance changes

* test: updated estimation assertion
  • Loading branch information
hui-an-yang authored Apr 17, 2024
1 parent bb8a273 commit b660df9
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 82 deletions.
72 changes: 36 additions & 36 deletions integration-tests/__tests__/contract/estimation-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const estimate = await LowAmountTez.estimate.transfer({ to: await Tezos.signer.publicKeyHash(), amount: 0.019 });
expect(estimate.gasLimit).toEqual(101);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(186);
expect(estimate.suggestedFeeMutez).toEqual(188);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(166);
expect(estimate.totalCost).toEqual(166);
expect(estimate.usingBaseFeeMutez).toEqual(166);
expect(estimate.minimalFeeMutez).toEqual(168);
expect(estimate.totalCost).toEqual(168);
expect(estimate.usingBaseFeeMutez).toEqual(168);
expect(estimate.consumedMilligas).toEqual(100040);
});

it('Verify .estimate.transfer with unallocated destination', async () => {
const estimate = await LowAmountTez.estimate.transfer({ to: await (await createAddress()).signer.publicKeyHash(), amount: 0.017 });
expect(estimate.gasLimit).toEqual(101);
expect(estimate.storageLimit).toEqual(277);
expect(estimate.suggestedFeeMutez).toEqual(186);
expect(estimate.suggestedFeeMutez).toEqual(188);
expect(estimate.burnFeeMutez).toEqual(69250);
expect(estimate.minimalFeeMutez).toEqual(166);
expect(estimate.totalCost).toEqual(69416);
expect(estimate.usingBaseFeeMutez).toEqual(166);
expect(estimate.minimalFeeMutez).toEqual(168);
expect(estimate.totalCost).toEqual(69418);
expect(estimate.usingBaseFeeMutez).toEqual(168);
expect(estimate.consumedMilligas).toEqual(100040);
});

Expand All @@ -69,11 +69,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
});
expect(estimate.gasLimit).toEqual(677);
expect(estimate.storageLimit).toEqual(591);
expect(estimate.suggestedFeeMutez).toEqual(535);
expect(estimate.suggestedFeeMutez).toEqual(537);
expect(estimate.burnFeeMutez).toEqual(147750);
expect(estimate.minimalFeeMutez).toEqual(515);
expect(estimate.totalCost).toEqual(148265);
expect(estimate.usingBaseFeeMutez).toEqual(515);
expect(estimate.minimalFeeMutez).toEqual(517);
expect(estimate.totalCost).toEqual(148267);
expect(estimate.usingBaseFeeMutez).toEqual(517);
expect(estimate.consumedMilligas).toEqual(676402);
});

Expand All @@ -84,11 +84,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
});
expect(estimate.gasLimit).toEqual(100);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(181);
expect(estimate.suggestedFeeMutez).toEqual(183);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(161);
expect(estimate.totalCost).toEqual(161);
expect(estimate.usingBaseFeeMutez).toEqual(161);
expect(estimate.minimalFeeMutez).toEqual(163);
expect(estimate.totalCost).toEqual(163);
expect(estimate.usingBaseFeeMutez).toEqual(163);
expect(estimate.consumedMilligas).toEqual(100000);
});

Expand All @@ -97,11 +97,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(1457);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(394);
expect(estimate.suggestedFeeMutez).toEqual(396);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(374);
expect(estimate.totalCost).toEqual(374);
expect(estimate.usingBaseFeeMutez).toEqual(374);
expect(estimate.minimalFeeMutez).toEqual(376);
expect(estimate.totalCost).toEqual(376);
expect(estimate.usingBaseFeeMutez).toEqual(376);
expect(estimate.consumedMilligas).toEqual(1456142);
});

Expand All @@ -114,11 +114,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(1571);
expect(estimate.storageLimit).toEqual(534);
expect(estimate.suggestedFeeMutez).toEqual(465);
expect(estimate.suggestedFeeMutez).toEqual(467);
expect(estimate.burnFeeMutez).toEqual(133500);
expect(estimate.minimalFeeMutez).toEqual(445);
expect(estimate.totalCost).toEqual(133945);
expect(estimate.usingBaseFeeMutez).toEqual(445);
expect(estimate.minimalFeeMutez).toEqual(447);
expect(estimate.totalCost).toEqual(133947);
expect(estimate.usingBaseFeeMutez).toEqual(447);
expect(estimate.consumedMilligas).toEqual(1570671);
});

Expand All @@ -127,11 +127,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(1867);
expect(estimate.storageLimit).toEqual(337);
expect(estimate.suggestedFeeMutez).toEqual(441);
expect(estimate.suggestedFeeMutez).toEqual(443);
expect(estimate.burnFeeMutez).toEqual(84250);
expect(estimate.minimalFeeMutez).toEqual(421);
expect(estimate.totalCost).toEqual(84671);
expect(estimate.usingBaseFeeMutez).toEqual(421);
expect(estimate.minimalFeeMutez).toEqual(423);
expect(estimate.totalCost).toEqual(84673);
expect(estimate.usingBaseFeeMutez).toEqual(423);
expect(estimate.consumedMilligas).toEqual(1866766);
});

Expand All @@ -140,11 +140,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(2392);
expect(estimate.storageLimit).toEqual(654);
expect(estimate.suggestedFeeMutez).toEqual(559);
expect(estimate.suggestedFeeMutez).toEqual(561);
expect(estimate.burnFeeMutez).toEqual(163500);
expect(estimate.minimalFeeMutez).toEqual(539);
expect(estimate.totalCost).toEqual(164039);
expect(estimate.usingBaseFeeMutez).toEqual(539);
expect(estimate.minimalFeeMutez).toEqual(541);
expect(estimate.totalCost).toEqual(164041);
expect(estimate.usingBaseFeeMutez).toEqual(541);
expect(estimate.consumedMilligas).toEqual(2391919);
// Do the actual operation
const op2 = await contract.methods.do(originate2()).send();
Expand Down Expand Up @@ -176,11 +176,11 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
let estimate = await LowAmountTez.estimate.transfer({ to: await Tezos.signer.publicKeyHash(), mutez: true, amount: amt - (1382 + getRevealFee(await LowAmountTez.signer.publicKeyHash())) });
expect(estimate.gasLimit).toEqual(101);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(185);
expect(estimate.suggestedFeeMutez).toEqual(187);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(165);
expect(estimate.totalCost).toEqual(165);
expect(estimate.usingBaseFeeMutez).toEqual(165);
expect(estimate.minimalFeeMutez).toEqual(167);
expect(estimate.totalCost).toEqual(167);
expect(estimate.usingBaseFeeMutez).toEqual(167);
expect(estimate.consumedMilligas).toEqual(100040);
});

Expand Down
15 changes: 11 additions & 4 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,33 @@ export interface Inode {
export interface DelegatesResponse {
full_balance?: BigNumber;
current_frozen_deposits?: BigNumber;
frozen_deposits?: BigNumber;
staking_balance: BigNumber;
frozen_deposits_limit?: BigNumber;
delegated_contracts: string[];
delegated_balance: BigNumber;
min_delegated_in_current_cycle?: MinDelegatedInCurrentCycle;
deactivated: boolean;
grace_period: number;
total_delegated_stake?: BigNumber;
staking_denominator?: BigNumber;
active_consensus_key?: string;
grace_period: number;
pending_denunciations?: boolean;
frozen_deposits_limit?: BigNumber;
voting_power?: BigNumber;
current_ballot?: BallotVote;
current_proposals?: string[];
remaining_proposals?: number;
active_consensus_key?: string;
pending_consensus_keys?: PendingConsensusKey[];
balance?: BigNumber;
frozen_deposits?: BigNumber;
frozen_balance?: BigNumber;
frozen_balance_by_cycle?: Frozenbalancebycycle[];
}

export type MinDelegatedInCurrentCycle = {
amount: string;
level?: LevelInfo;
};

export type PendingConsensusKey = {
cycle: number;
pkh: string;
Expand Down
30 changes: 23 additions & 7 deletions packages/taquito-rpc/test/data/rpc-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2304,14 +2304,30 @@ export const managerKey = 'edpkvP1NXoo8vhYbPSvXdy466EHoYWBpf6zmjghB2p3DwJPjbB5ns
export const delegate = 'tz1cjyja1TU6fiyiFav3mFAdnDsCReJ12hPD';
export const bigmapValue = { prim: 'Pair', args: [[], { int: '100' }] };
export const delegates = {
full_balance: new BigNumber('10289576365'),
current_frozen_deposits: new BigNumber('2028957741'),
frozen_deposits: new BigNumber('1028957741'),
staking_balance: new BigNumber('10289576365'),
delegated_contracts: ['tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb'],
delegated_balance: new BigNumber('0'),
min_delegated_in_current_cycle: {
amount: '8260618624',
level: {
level: 81924,
level_position: 81923,
cycle: 7,
cycle_position: 3,
expected_commitment: false,
},
},
deactivated: false,
balance: new BigNumber('5821087107868'),
frozen_balance: new BigNumber('1682643263470'),
staking_balance: new BigNumber('5792534034676'),
delegated_contracts: ['tz2ApgXezUaJKaY49nxEYbMjsjnkAz2mTiFC'],
delegated_balance: new BigNumber('12714439280'),
grace_period: 131,
voting_power: 747,
grace_period: 7,
pending_denunciations: false,
total_delegated_stake: new BigNumber('0'),
staking_denominator: new BigNumber('0'),
voting_power: new BigNumber('10289577405'),
remaining_proposals: 20,
active_consensus_key: 'tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb',
};
export const votingInfo = {
voting_power: '1005169895965',
Expand Down
80 changes: 45 additions & 35 deletions packages/taquito-rpc/test/taquito-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,30 @@ describe('RpcClient test', () => {

describe('getDelegates', () => {
const sampleResponse = {
balance: '5092341810457',
frozen_balance: '2155290163074',
frozen_balance_by_cycle: [
{ cycle: 135, deposit: '381760000000', fees: '971071', rewards: '11843833332' },
{ cycle: 136, deposit: '394368000000', fees: '1433657', rewards: '12200333332' },
],
staking_balance: '20936607331513',
delegated_contracts: [
'KT1VvXEpeBpreAVpfp4V8ZujqWu2gVykwXBJ',
'KT1VsSxSXUkgw6zkBGgUuDXXuJs9ToPqkrCg',
],
delegated_balance: '15908924646030',
full_balance: new BigNumber('10289576365'),
current_frozen_deposits: new BigNumber('2028957741'),
frozen_deposits: new BigNumber('1028957741'),
staking_balance: new BigNumber('10289576365'),
delegated_contracts: ['tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb'],
delegated_balance: new BigNumber('0'),
min_delegated_in_current_cycle: {
amount: '8260618624',
level: {
level: 81924,
level_position: 81923,
cycle: 7,
cycle_position: 3,
expected_commitment: false,
},
},
deactivated: false,
grace_period: 146,
grace_period: 7,
pending_denunciations: false,
total_delegated_stake: new BigNumber('0'),
staking_denominator: new BigNumber('0'),
voting_power: new BigNumber('10289577405'),
remaining_proposals: 20,
active_consensus_key: 'tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb',
};

it('should query the right url', async () => {
Expand All @@ -262,30 +272,30 @@ describe('RpcClient test', () => {
const response = await client.getDelegates(contractAddress);

expect(response).toEqual({
balance: new BigNumber('5092341810457'),
frozen_balance: new BigNumber('2155290163074'),
frozen_balance_by_cycle: [
{
cycle: 135,
deposit: new BigNumber('381760000000'),
fees: new BigNumber('971071'),
rewards: new BigNumber('11843833332'),
},
{
cycle: 136,
deposit: new BigNumber('394368000000'),
fees: new BigNumber('1433657'),
rewards: new BigNumber('12200333332'),
full_balance: new BigNumber('10289576365'),
current_frozen_deposits: new BigNumber('2028957741'),
frozen_deposits: new BigNumber('1028957741'),
staking_balance: new BigNumber('10289576365'),
delegated_contracts: ['tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb'],
delegated_balance: new BigNumber('0'),
min_delegated_in_current_cycle: {
amount: '8260618624',
level: {
level: 81924,
level_position: 81923,
cycle: 7,
cycle_position: 3,
expected_commitment: false,
},
],
staking_balance: new BigNumber('20936607331513'),
delegated_contracts: [
'KT1VvXEpeBpreAVpfp4V8ZujqWu2gVykwXBJ',
'KT1VsSxSXUkgw6zkBGgUuDXXuJs9ToPqkrCg',
],
delegated_balance: new BigNumber('15908924646030'),
},
deactivated: false,
grace_period: 146,
grace_period: 7,
pending_denunciations: false,
total_delegated_stake: new BigNumber('0'),
staking_denominator: new BigNumber('0'),
voting_power: new BigNumber('10289577405'),
remaining_proposals: 20,
active_consensus_key: 'tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb',
});
});

Expand Down

0 comments on commit b660df9

Please sign in to comment.