Skip to content

Commit

Permalink
fix: add rpc method to get origination proof and modify tests and met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
Zainen Suzuki authored and Zainen Suzuki committed Mar 9, 2023
1 parent d1473b8 commit d8dd410
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 15 deletions.
4 changes: 2 additions & 2 deletions integration-tests/contract-smart-rollup-originate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ CONFIGS().forEach(({ lib, rpc, setup, protocol }) => {
done()
})

mondayAndAlpha('verify that contract.reveal reveals the current account', async (done) => {
mondayAndAlpha('verify smart rollup originate origination', async (done) => {
const op = await Tezos.contract.smartRollupOriginate({
pvmKind: PvmKind.WASM2,
kernel: '23212f7573722f62696e2f656e762073680a6578706f7274204b45524e454c3d22303036313733366430313030303030303031323830373630303337663766376630313766363030323766376630313766363030353766376637663766376630313766363030313766303036303031376630313766363030323766376630303630303030303032363130333131373336643631373237343566373236663663366337353730356636333666373236353061373236353631363435663639366537303735373430303030313137333664363137323734356637323666366336633735373035663633366637323635306337373732363937343635356636663735373437303735373430303031313137333664363137323734356637323666366336633735373035663633366637323635306237333734366637323635356637373732363937343635303030323033303530343033303430353036303530333031303030313037313430323033366436353664303230303061366236353732366536353663356637323735366530303036306161343031303432613031303237663431666130303266303130303231303132303030326630313030323130323230303132303032343730343430343165343030343131323431303034316534303034313030313030323161306230623038303032303030343163343030366230623530303130353766343166653030326430303030323130333431666330303266303130303231303232303030326430303030323130343230303032663031303032313035323030313130303432313036323030343230303334363034343032303030343130313661323030313431303136623130303131613035323030353230303234363034343032303030343130373661323030363130303131613062306230623164303130313766343164633031343138343032343139303163313030303231303034313834303232303030313030353431383430323130303330623062333830353030343165343030306231323266366236353732366536353663326636353665373632663732363536323666366637343030343166383030306230323030303130303431666130303062303230303032303034316663303030623032303030303030343166653030306230313031220a',
originationProof: '0300020c4a316fa1079bfc23dac5ecc609ab10e26490e378a81e774c51176040bea18030fab8a3adde4b553c4d391e9cd19ee13b17941c1f49c040d621bbfbea964993810764757261626c658108726561646f6e6c79d00b749948da9186d29aed2f9327b46793f18b1e6499c40f0ddbf0bf785e85e2e9',
parametersType: { prim: 'bytes' },

});
await op.confirmation();

expect(op.status).toEqual('applied')
done();
});
Expand Down
7 changes: 7 additions & 0 deletions packages/taquito-contracts-library/src/rpc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
VotingPeriodBlockResult,
TicketTokenParams,
AllTicketBalances,
OriginationProofParams,
} from '@taquito/rpc';
import { ContractsLibrary } from './taquito-contracts-library';

Expand Down Expand Up @@ -321,4 +322,10 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
): Promise<AllTicketBalances> {
return this.rpc.getAllTicketBalances(contract, { block });
}
async getOriginationProof(
reqs: OriginationProofParams,
{ block }: RPCOptions = defaultRPCOptions
): Promise<string> {
return this.rpc.getOriginationProof(reqs, { block });
}
}
3 changes: 3 additions & 0 deletions packages/taquito-rpc/src/rpc-client-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
VotingPeriodBlockResult,
TicketTokenParams,
AllTicketBalances,
OriginationProofParams,
} from './types';

export interface RPCOptions {
Expand Down Expand Up @@ -127,6 +128,7 @@ export interface RpcClientInterface {
options?: RPCOptions
): Promise<string>;
getAllTicketBalances(contract: string, options?: RPCOptions): Promise<AllTicketBalances>;
getOriginationProof(reqs: OriginationProofParams, options?: RPCOptions): Promise<string>;
}

export enum RPCMethodName {
Expand Down Expand Up @@ -169,4 +171,5 @@ export enum RPCMethodName {
GET_STORAGE_PAID_SPACE = 'getStoragePaidSpace',
GET_TICKET_BALANCE = 'getTicketBalance',
GET_ALL_TICKET_BALANCES = 'getAllTicketBalances',
GET_ORIGINATION_PROOF = 'getOriginationProof',
}
22 changes: 21 additions & 1 deletion packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
VotingPeriodBlockResult,
TicketTokenParams,
AllTicketBalances,
OriginationProofParams,
} from '../types';

import {
Expand All @@ -70,7 +71,8 @@ type RpcMethodParam =
| UnparsingMode
| BigMapKey
| BakingRightsQueryArguments
| EndorsingRightsQueryArguments;
| EndorsingRightsQueryArguments
| OriginationProofParams;

const defaultTtl = 1000;

Expand Down Expand Up @@ -1224,4 +1226,22 @@ export class RpcClientCache implements RpcClientInterface {
return response;
}
}

async getOriginationProof(
reqs: OriginationProofParams,
{ block }: RPCOptions = defaultRPCOptions
): Promise<string> {
const key = this.formatCacheKey(
this.rpcClient.getRpcUrl(),
RPCMethodName.GET_ORIGINATION_PROOF,
[block, reqs]
);
if (this.has(key)) {
return this.get(key);
} else {
const response = this.rpcClient.getOriginationProof(reqs, { block });
this.put(key, response);
return response;
}
}
}
16 changes: 16 additions & 0 deletions packages/taquito-rpc/src/taquito-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
TxRollupInboxResponse,
TicketTokenParams,
AllTicketBalances,
OriginationProofParams,
} from './types';
import { castToBigNumber } from './utils/utils';
import {
Expand Down Expand Up @@ -1172,4 +1173,19 @@ export class RpcClient implements RpcClientInterface {
method: 'GET',
});
}

async getOriginationProof(
params: OriginationProofParams,
{ block }: { block: string } = defaultRPCOptions
): Promise<string> {
return this.httpBackend.createRequest<string>(
{
url: this.createURL(
`/chains/${this.chain}/blocks/${block}/context/smart_rollups/all/origination_proof`
),
method: 'POST',
},
params
);
}
}
5 changes: 5 additions & 0 deletions packages/taquito-rpc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2083,3 +2083,8 @@ export enum PvmKind {
WASM2 = 'wasm_2_0_0',
ARITH = 'arith',
}

export interface OriginationProofParams {
kind: PvmKind;
kernel: string;
}
4 changes: 2 additions & 2 deletions packages/taquito/src/contract/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
RPCProposalsOperation,
UpdateConsensusKeyParams,
RPCUpdateConsensusKeyOperation,
SmartRollupOriginateParams,
RPCSmartRollupOriginateOperation,
SmartRollupOriginateParamsWithProof,
} from '../operations/types';
import { DEFAULT_FEE, DEFAULT_GAS_LIMIT, DEFAULT_STORAGE_LIMIT } from '../constants';
import { format } from '@taquito/utils';
Expand Down Expand Up @@ -331,7 +331,7 @@ export const createSmartRollupOriginateOperation = async ({
kernel,
originationProof,
parametersType,
}: SmartRollupOriginateParams) => {
}: SmartRollupOriginateParamsWithProof) => {
return {
kind: OpKind.SMART_ROLLUP_ORIGINATE,
source,
Expand Down
8 changes: 7 additions & 1 deletion packages/taquito/src/contract/rpc-contract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,14 @@ export class RpcContractProvider
params,
this.estimator.smartRollupOriginate.bind(this.estimator)
);
const originationProof = await this.rpc.getOriginationProof({
kind: params.pvmKind,
kernel: params.kernel,
});
const completeParams = { ...params, originationProof };

const operation = await createSmartRollupOriginateOperation({
...params,
...completeParams,
...estimate,
});
const ops = await this.addRevealOperationIfNeeded(operation, publicKeyHash);
Expand Down
8 changes: 7 additions & 1 deletion packages/taquito/src/estimate/rpc-estimate-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,15 @@ export class RPCEstimateProvider extends OperationEmitter implements EstimationP
const pkh = (await this.getKeys()).publicKeyHash;
const protocolConstants = await this.context.readProvider.getProtocolConstants('head');

const originationProof = await this.rpc.getOriginationProof({
kind: params.pvmKind,
kernel: params.kernel,
});
const completeRest = { ...rest, originationProof };

const DEFAULT_PARAMS = await this.getAccountLimits(pkh, protocolConstants);
const op = await createSmartRollupOriginateOperation({
...rest,
...completeRest,
...mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS),
});
const isRevealNeeded = await this.isRevealOpNeeded([op], pkh);
Expand Down
4 changes: 3 additions & 1 deletion packages/taquito/src/operations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,11 @@ export interface SmartRollupOriginateParams {
storageLimit?: number;
pvmKind: PvmKind;
kernel: string;
originationProof: string;
parametersType: MichelsonV1Expression;
}
export interface SmartRollupOriginateParamsWithProof extends SmartRollupOriginateParams {
originationProof: string;
}

export interface RPCSmartRollupOriginateOperation {
kind: OpKind.SMART_ROLLUP_ORIGINATE;
Expand Down
9 changes: 7 additions & 2 deletions packages/taquito/src/prepare/prepare-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,17 @@ export class PrepareProvider implements PreparationProvider {
*/
async smartRollupOriginate(params: SmartRollupOriginateParams): Promise<PreparedOperation> {
const pkh = await this.signer.publicKeyHash();
const originationProof = await this.rpc.getOriginationProof({
kind: params.pvmKind,
kernel: params.kernel,
});
const completeParams = { ...params, originationProof };

const estimate = await this.estimate.smartRollupOriginate(params);
const estimate = await this.estimate.smartRollupOriginate(completeParams);
const estimates = this.buildEstimates(estimate);

const op = await createSmartRollupOriginateOperation({
...params,
...completeParams,
...estimates,
});

Expand Down
10 changes: 8 additions & 2 deletions packages/taquito/test/contract/rpc-contract-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('RpcContractProvider test', () => {
getSaplingDiffById: jest.Mock<any, any>;
getProtocols: jest.Mock<any, any>;
getCurrentPeriod: jest.Mock<any, any>;
getOriginationProof: jest.Mock<any, any>;
};

let mockSigner: {
Expand Down Expand Up @@ -118,6 +119,7 @@ describe('RpcContractProvider test', () => {
getSaplingDiffById: jest.fn(),
getProtocols: jest.fn(),
getCurrentPeriod: jest.fn(),
getOriginationProof: jest.fn(),
};

mockForger = {
Expand Down Expand Up @@ -2254,12 +2256,13 @@ describe('RpcContractProvider test', () => {
it('Should have correct returned values with origination', async (done) => {
const estimate = new Estimate(1230000, 10000, 100, 100);
mockEstimate.smartRollupOriginate.mockResolvedValue(estimate);
mockRpcClient.getOriginationProof.mockResolvedValue(
'0300020c4a316fa1079bfc23dac5ecc609ab10e26490e378a81e774c51176040bea180467070f4682a44b982768d522ec6380982f446488c0176ed7c13aa1d6c12a03a810764757261626c658108726561646f6e6c79d00b749948da9186d29aed2f9327b46793f18b1e6499c40f0ddbf0bf785e85e2e9'
);
const smartRollupOriginate = await rpcContractProvider.smartRollupOriginate({
pvmKind: PvmKind.WASM2,
kernel:
'0061736d0100000001280760037f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f0060000002610311736d6172745f726f6c6c75705f636f72650a726561645f696e707574000011736d6172745f726f6c6c75705f636f72650c77726974655f6f7574707574000111736d6172745f726f6c6c75705f636f72650b73746f72655f77726974650002030504030405060503010001071402036d656d02000a6b65726e656c5f72756e00060aa401042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b5001057f41fe002d0000210341fc002f0100210220002d0000210420002f0100210520011004210620042003460440200041016a200141016b10011a0520052002460440200041076a200610011a0b0b0b1d01017f41dc0141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101',
originationProof:
'0300020c4a316fa1079bfc23dac5ecc609ab10e26490e378a81e774c51176040bea180467070f4682a44b982768d522ec6380982f446488c0176ed7c13aa1d6c12a03a810764757261626c658108726561646f6e6c79d00b749948da9186d29aed2f9327b46793f18b1e6499c40f0ddbf0bf785e85e2e9',
parametersType: {
prim: 'bytes',
},
Expand All @@ -2268,6 +2271,9 @@ describe('RpcContractProvider test', () => {
expect(smartRollupOriginate.storageLimit).toEqual(10000);
expect(smartRollupOriginate.gasLimit).toEqual(1330);
expect(smartRollupOriginate.fee).toEqual(433);
expect(smartRollupOriginate.originationProof).toEqual(
'0300020c4a316fa1079bfc23dac5ecc609ab10e26490e378a81e774c51176040bea180467070f4682a44b982768d522ec6380982f446488c0176ed7c13aa1d6c12a03a810764757261626c658108726561646f6e6c79d00b749948da9186d29aed2f9327b46793f18b1e6499c40f0ddbf0bf785e85e2e9'
);

done();
});
Expand Down
6 changes: 4 additions & 2 deletions packages/taquito/test/estimate/rpc-estimate-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ describe('RPCEstimateProvider test wallet', () => {
getChainId: jest.Mock<any, any>;
getConstants: jest.Mock<any, any>;
getProtocols: jest.Mock<any, any>;
getOriginationProof: jest.Mock<any, any>;
};

let mockForger: {
Expand All @@ -1303,6 +1304,7 @@ describe('RPCEstimateProvider test wallet', () => {
getChainId: jest.fn(),
getConstants: jest.fn(),
getProtocols: jest.fn(),
getOriginationProof: jest.fn(),
};

mockForger = {
Expand Down Expand Up @@ -1724,12 +1726,12 @@ describe('RPCEstimateProvider test wallet', () => {
describe('smartRollupOriginate', () => {
it('Should return the correct estimate for SmartRollupOriginate operation', async (done) => {
mockRpcClient.runOperation.mockResolvedValue(smartRollupOriginateWithReveal);
mockRpcClient.getOriginationProof.mockResolvedValue('987654321');

const estimate = await estimateProvider.smartRollupOriginate({
pvmKind: PvmKind.WASM2,
kernel:
'0061736d0100000001280760037f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f0060000002610311736d6172745f726f6c6c75705f636f72650a726561645f696e707574000011736d6172745f726f6c6c75705f636f72650c77726974655f6f7574707574000111736d6172745f726f6c6c75705f636f72650b73746f72655f77726974650002030504030405060503010001071402036d656d02000a6b65726e656c5f72756e00060aa401042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b5001057f41fe002d0000210341fc002f0100210220002d0000210420002f0100210520011004210620042003460440200041016a200141016b10011a0520052002460440200041076a200610011a0b0b0b1d01017f41dc0141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101',
originationProof:
'0300020c4a316fa1079bfc23dac5ecc609ab10e26490e378a81e774c51176040bea180467070f4682a44b982768d522ec6380982f446488c0176ed7c13aa1d6c12a03a810764757261626c658108726561646f6e6c79d00b749948da9186d29aed2f9327b46793f18b1e6499c40f0ddbf0bf785e85e2e9',
parametersType: {
prim: 'bytes',
},
Expand Down
4 changes: 3 additions & 1 deletion packages/taquito/test/prepare/prepare-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('PrepareProvider test', () => {
getCurrentPeriod: jest.Mock<any, any>;
getConstants: jest.Mock<any, any>;
getManagerKey: jest.Mock<any, any>;
getOriginationProof: jest.Mock<any, any>;
};

let mockSigner: {
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('PrepareProvider test', () => {
getCurrentPeriod: jest.fn(),
getConstants: jest.fn(),
getManagerKey: jest.fn(),
getOriginationProof: jest.fn(),
};

mockSigner = {
Expand Down Expand Up @@ -1002,13 +1004,13 @@ describe('PrepareProvider test', () => {
describe('SmartRollupOriginate', () => {
it('Should prepare smartRollupOriginate without reveal', async (done) => {
mockReadProvider.isAccountRevealed.mockResolvedValue(true);
mockRpcClient.getOriginationProof.mockResolvedValue('987654321');

jest.spyOn(context.estimate, 'smartRollupOriginate').mockResolvedValue(estimate);

const prepared = await prepareProvider.smartRollupOriginate({
pvmKind: PvmKind.WASM2,
kernel: '123456789',
originationProof: '987654321',
parametersType: {
prim: 'bytes',
},
Expand Down

0 comments on commit d8dd410

Please sign in to comment.