Skip to content

Commit

Permalink
2884 remove get endorsing rights (#2916)
Browse files Browse the repository at this point in the history
* feat: removed rpc.getEndorsingRights

* docs: update getBlock desc with default version 1

* test: updated estimation assertion

* test: updated estimation assertion

* test: updated estimation assertion
  • Loading branch information
hui-an-yang authored and ac10n committed May 2, 2024
1 parent 8c56d90 commit e362f98
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 234 deletions.
2 changes: 0 additions & 2 deletions docs/rpc_nodes_integration_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Test calling all methods from RPC node: https://a-node
✓ Verify that rpcClient.getBlockMetadata returns all metadata associated to the block (17 ms)
✓ Verify that rpcClient.getBakingRights retrieves the list of delegates allowed to bake a block (14 ms)
✓ Verify that rpcClient.getAttestationRights retrieves the list of delegates allowed to attest a block (25 ms)
✓ Verify that rpcClient.getEndorsingRights retrieves the list of delegates allowed to endorse a block (19 ms)
✓ Verify that rpcClient.getBallotList returns ballots casted so far during a voting period (10 ms)
✓ Verify that rpcClient.getBallots returns sum of ballots casted so far during a voting period (39 ms)
✓ Verify that rpcClient.getCurrentPeriod returns current period kind (11 ms)
Expand Down Expand Up @@ -83,7 +82,6 @@ Test calling all methods from RPC node: https://another-node
✓ Verify that rpcClient.getBlockMetadata returns all metadata associated to the block (1472 ms)
✕ Verify that rpcClient.getBakingRights retrieves the list of delegates allowed to bake a block (479 ms)
✓ Verify that rpcClient.getAttestationRights retrieves the list of delegates allowed to attest a block (1487 ms)
✕ Verify that rpcClient.getEndorsingRights retrieves the list of delegates allowed to endorse a block (539 ms)
✓ Verify that rpcClient.getBallotList returns ballots casted so far during a voting period (615 ms)
✓ Verify that rpcClient.getBallots returns sum of ballots casted so far during a voting period (1670 ms)
✓ Verify that rpcClient.getCurrentPeriod returns current period kind (487 ms)
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/__tests__/contract/estimation-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
it('Verify .estimate.transfer for internal transfer to allocated implicit', async () => {
const tx = contract.methods.do(MANAGER_LAMBDA.transferImplicit(knownBaker, 5)).toTransferParams();
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(1456);
expect(estimate.gasLimit).toEqual(1457);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(394);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(374);
expect(estimate.totalCost).toEqual(374);
expect(estimate.usingBaseFeeMutez).toEqual(374);
expect(estimate.consumedMilligas).toEqual(1455884);
expect(estimate.consumedMilligas).toEqual(1456056);
});

it('Verify .estimate.transfer for multiple internal transfers to unallocated account', async () => {
Expand All @@ -119,7 +119,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
expect(estimate.minimalFeeMutez).toEqual(445);
expect(estimate.totalCost).toEqual(133945);
expect(estimate.usingBaseFeeMutez).toEqual(445);
expect(estimate.consumedMilligas).toEqual(1570413);
expect(estimate.consumedMilligas).toEqual(1570585);
});

it('Verify .estimate.transfer for internal origination', async () => {
Expand All @@ -132,7 +132,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
expect(estimate.minimalFeeMutez).toEqual(421);
expect(estimate.totalCost).toEqual(84671);
expect(estimate.usingBaseFeeMutez).toEqual(421);
expect(estimate.consumedMilligas).toEqual(1866508);
expect(estimate.consumedMilligas).toEqual(1866680);
});

it('Verify .estimate.transfer for multiple internal originations', async () => {
Expand All @@ -145,7 +145,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
expect(estimate.minimalFeeMutez).toEqual(539);
expect(estimate.totalCost).toEqual(164039);
expect(estimate.usingBaseFeeMutez).toEqual(539);
expect(estimate.consumedMilligas).toEqual(2391661);
expect(estimate.consumedMilligas).toEqual(2391833);
// Do the actual operation
const op2 = await contract.methods.do(originate2()).send();
await op2.confirmation();
Expand Down
13 changes: 0 additions & 13 deletions integration-tests/__tests__/rpc/nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,6 @@ CONFIGS().forEach(
expect(attestationRights[0].delegate).toBeUndefined();
});

unrestrictedRPCNode('Verify that rpcClient.getEndorsingRights retrieves the list of delegates allowed to endorse a block', async () => {
const endorsingRights = await rpcClient.getEndorsingRights();
expect(endorsingRights).toBeDefined();
expect(endorsingRights[0].delegates).toBeDefined();
expect(endorsingRights[0].delegates![0].delegate).toBeDefined();
expect(typeof endorsingRights[0].delegates![0].delegate).toEqual('string');
expect(endorsingRights[0].delegates![0].endorsing_power).toBeDefined();
expect(typeof endorsingRights[0].delegates![0].endorsing_power).toEqual('number');
expect(endorsingRights[0].delegates![0].first_slot).toBeDefined();
expect(typeof endorsingRights[0].delegates![0].first_slot).toEqual('number');
expect(endorsingRights[0].delegate).toBeUndefined();
});

it('Verify that rpcClient.getBallotList returns ballots casted so far during a voting period', async () => {
const ballotList = await rpcClient.getBallotList();
expect(ballotList).toBeDefined();
Expand Down
10 changes: 1 addition & 9 deletions packages/taquito-contracts-library/src/rpc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
VotingInfoResponse,
AttestationRightsQueryArguments,
AttestationRightsResponse,
EndorsingRightsQueryArguments,
EndorsingRightsResponse,
EntrypointsResponse,
ForgeOperationsParams,
ManagerKeyResponse,
Expand Down Expand Up @@ -61,7 +59,7 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
constructor(
private rpc: RpcClientInterface,
private contractslibrary: ContractsLibrary
) {}
) { }

async getContract(
address: string,
Expand Down Expand Up @@ -180,12 +178,6 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
): Promise<AttestationRightsResponse> {
return this.rpc.getAttestationRights(args, { block });
}
async getEndorsingRights(
args: EndorsingRightsQueryArguments,
{ block }: RPCOptions = defaultRPCOptions
): Promise<EndorsingRightsResponse> {
return this.rpc.getEndorsingRights(args, { block });
}
async getBallotList({ block }: RPCOptions = defaultRPCOptions): Promise<BallotListResponse> {
return this.rpc.getBallotList({ block });
}
Expand Down
7 changes: 0 additions & 7 deletions packages/taquito-rpc/src/rpc-client-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
DelegatesResponse,
AttestationRightsQueryArguments,
AttestationRightsResponse,
EndorsingRightsQueryArguments,
EndorsingRightsResponse,
EntrypointsResponse,
ForgeOperationsParams,
ManagerKeyResponse,
Expand Down Expand Up @@ -90,10 +88,6 @@ export interface RpcClientInterface {
args: AttestationRightsQueryArguments,
options?: RPCOptions
): Promise<AttestationRightsResponse>;
getEndorsingRights(
args: EndorsingRightsQueryArguments,
options?: RPCOptions
): Promise<EndorsingRightsResponse>;
getBallotList(options?: RPCOptions): Promise<BallotListResponse>;
getBallots(options?: RPCOptions): Promise<BallotsResponse>;
getCurrentProposal(options?: RPCOptions): Promise<CurrentProposalResponse>;
Expand Down Expand Up @@ -157,7 +151,6 @@ export enum RPCMethodName {
GET_DELEGATES = 'getDelegates',
GET_VOTING_INFO = 'getVotingInfo',
GET_ATTESTATION_RIGHTS = 'getAttestationRights',
GET_ENDORSING_RIGHTS = 'getEndorsingRights',
GET_ENTRYPOINTS = 'getEntrypoints',
GET_LIVE_BLOCKS = 'getLiveBlocks',
GET_MANAGER_KEY = 'getManagerKey',
Expand Down
31 changes: 1 addition & 30 deletions packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {
VotingInfoResponse,
AttestationRightsQueryArguments,
AttestationRightsResponse,
EndorsingRightsQueryArguments,
EndorsingRightsResponse,
EntrypointsResponse,
ForgeOperationsParams,
ManagerKeyResponse,
Expand Down Expand Up @@ -75,7 +73,6 @@ type RpcMethodParam =
| BakingRightsQueryArguments
| PendingOperationsQueryArguments
| AttestationRightsQueryArguments
| EndorsingRightsQueryArguments;

const defaultTtl = 1000;

Expand All @@ -94,7 +91,7 @@ export class RpcClientCache implements RpcClientInterface {
constructor(
private rpcClient: RpcClientInterface,
private ttl = defaultTtl
) {}
) { }

getAllCachedData() {
return this._cache;
Expand Down Expand Up @@ -572,7 +569,6 @@ export class RpcClientCache implements RpcClientInterface {
* @param args contains optional query arguments (level, cycle, delegate, and consensus_key)
* @param options contains generic configuration for rpc calls to specified block (default to head)
* @description Retrieves the delegates allowed to attest a block
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-helpers-endorsing-rights
*/
async getAttestationRights(
args: AttestationRightsQueryArguments = {},
Expand All @@ -592,31 +588,6 @@ export class RpcClientCache implements RpcClientInterface {
}
}

/**
* @deprecated Deprecated in favor of getAttestationRights
* @param args contains optional query arguments (level, cycle, delegate, and consensus_key)
* @param options contains generic configuration for rpc calls
* @description Retrieves the delegates allowed to endorse a block
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-helpers-endorsing-rights
*/
async getEndorsingRights(
args: EndorsingRightsQueryArguments = {},
{ block }: RPCOptions = defaultRPCOptions
): Promise<EndorsingRightsResponse> {
const key = this.formatCacheKey(
this.rpcClient.getRpcUrl(),
RPCMethodName.GET_ENDORSING_RIGHTS,
[block, args]
);
if (this.has(key)) {
return this.get(key);
} else {
const response = this.rpcClient.getEndorsingRights(args, { block });
this.put(key, response);
return response;
}
}

/**
* @param options contains generic configuration for rpc calls to specified block (default to head)
* @description Ballots casted so far during a voting period
Expand Down
27 changes: 2 additions & 25 deletions packages/taquito-rpc/src/taquito-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import {
VotingInfoResponse,
AttestationRightsQueryArguments,
AttestationRightsResponse,
EndorsingRightsQueryArguments,
EndorsingRightsResponse,
EntrypointsResponse,
ForgeOperationsParams,
ManagerKeyResponse,
Expand Down Expand Up @@ -481,8 +479,8 @@ export class RpcClient implements RpcClientInterface {
* @param options contains generic configuration for rpc calls to specified block (default to head) and version.
* @description All the information about a block
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id
* @example getBlock() will default to `/main/chains/block/head?version=0` which shows { kind: endorsement }
* @example getBlock({ block: 'head~2', version: 1 }) will return an offset of 2 from head blocks and shows { kind: attestation }
* @example getBlock() will default to `/main/chains/block/head?version=1` which shows { kind: attestation }
* @example getBlock({ block: 'head~2', version: 0 }) will return an offset of 2 from head blocks and shows { kind: endorsement }
* @example getBlock({ block: 'BL8fTiWcSxWCjiMVnDkbh6EuhqVPZzgWheJ2dqwrxYRm9AephXh~2' }) will return an offset of 2 blocks from given block hash..
*/
async getBlock({ block, version }: RPCOptions = defaultRPCOptions): Promise<BlockResponse> {
Expand Down Expand Up @@ -552,7 +550,6 @@ export class RpcClient implements RpcClientInterface {
* @param args contains optional query arguments (level, cycle, delegate, and consensus_key)
* @param options contains generic configuration for rpc calls to specified block (default to head)
* @description Retrieves the delegates allowed to attest a block
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-helpers-endorsing-rights
*/
async getAttestationRights(
args: AttestationRightsQueryArguments = {},
Expand All @@ -567,26 +564,6 @@ export class RpcClient implements RpcClientInterface {
return response;
}

/**
* @deprecated Deprecated in favor of getAttestationRights
* @param args contains optional query arguments (level, cycle, delegate, and consensus_key)
* @param options contains generic configuration for rpc calls
* @description Retrieves the delegates allowed to endorse a block
* @see https://tezos.gitlab.io/api/rpc.html#get-block-id-helpers-endorsing-rights
*/
async getEndorsingRights(
args: EndorsingRightsQueryArguments = {},
{ block }: RPCOptions = defaultRPCOptions
): Promise<EndorsingRightsResponse> {
const response = await this.httpBackend.createRequest<EndorsingRightsResponse>({
url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/endorsing_rights`),
method: 'GET',
query: args,
});

return response;
}

/**
* @param options contains generic configuration for rpc calls to specified block (default to head)
* @description Ballots casted so far during a voting period
Expand Down
58 changes: 15 additions & 43 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ interface INodeExtender {

type OtherEltsInner =
| {
value: any;
}
value: any;
}
| {
inode_extender: INodeExtender;
};
inode_extender: INodeExtender;
};

export type OtherElts =
| {
node: [string, { value: string } | { node: string }][];
}
node: [string, { value: string } | { node: string }][];
}
| {
other_elts: OtherEltsInner;
};
other_elts: OtherEltsInner;
};

export interface Inode {
length: string;
Expand Down Expand Up @@ -1103,34 +1103,6 @@ export interface AttestationRightsResponseItem {

export type AttestationRightsResponse = AttestationRightsResponseItem[];

export type EndorsingRightsArgumentsDelegate = string | string[];
export type EndorsingRightsArgumentsCycle = number | number[];
export type EndorsingRightsArgumentsLevel = number | number[];

export interface EndorsingRightsQueryArguments {
level?: EndorsingRightsArgumentsLevel;
cycle?: EndorsingRightsArgumentsCycle;
delegate?: EndorsingRightsArgumentsDelegate;
consensus_key?: string;
}

export interface EndorsingRightsResponseItemDelegates {
delegate: string;
first_slot: number;
endorsing_power: number;
consensus_key?: string;
}

export interface EndorsingRightsResponseItem {
level: number;
delegate?: string;
delegates?: EndorsingRightsResponseItemDelegates[];
slots?: number[];
estimated_time?: Date;
}

export type EndorsingRightsResponse = EndorsingRightsResponseItem[];

export type BallotListResponseEnum = 'nay' | 'yay' | 'pass';

export interface BallotListResponseItem {
Expand Down Expand Up @@ -1994,10 +1966,10 @@ export interface ConstantsResponseProto010 extends ConstantsResponseProto009 {
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConstantsResponseProto009 extends ConstantsResponseProto008 {}
export interface ConstantsResponseProto009 extends ConstantsResponseProto008 { }

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConstantsResponseProto008 extends ConstantsResponseProto007 {}
export interface ConstantsResponseProto008 extends ConstantsResponseProto007 { }

export interface ConstantsResponseProto007
extends Omit<ConstantsResponseProto006, 'max_revelations_per_block'> {
Expand Down Expand Up @@ -2205,12 +2177,12 @@ export type ProtocolsResponse = {

export type Next =
| {
next: number;
}
next: number;
}
| {
newest: number;
oldest: number;
};
newest: number;
oldest: number;
};

export type LastRemovedCommitmentHashes = {
last_message_hash: string;
Expand Down
8 changes: 0 additions & 8 deletions packages/taquito-rpc/test/data/rpc-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2459,14 +2459,6 @@ export const attestationRights = [
],
},
];
export const endorsingRights = [
{
level: 516500,
delegate: 'tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5',
slots: [12, 37, 80, 120, 130, 206, 209, 219, 229],
estimated_time: '2021-09-27T20:41:55Z',
},
];
export const ballotList = [];
export const ballots = { yay: 0, nay: 0, pass: 0 };
export const currentPeriodKind = {
Expand Down
Loading

0 comments on commit e362f98

Please sign in to comment.