Skip to content

Commit

Permalink
fix: fix merge conflicts from lima
Browse files Browse the repository at this point in the history
  • Loading branch information
hui-an-yang committed Nov 26, 2022
2 parents ef91d64 + 5652389 commit 7e5a1b8
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 18 deletions.
4 changes: 2 additions & 2 deletions integration-tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const kathmandunetEphemeral = {
};

const limanetEphemeral = {
rpc: process.env['TEZOS_RPC_LIMANET'] || 'https://limanet.ecadinfra.com',
rpc: process.env['TEZOS_RPC_LIMANET'] || 'http://ecad-limanet-full:8732',
pollingIntervalMilliseconds: process.env['POLLING_INTERVAL_MILLISECONDS'] || undefined,
rpcCacheMilliseconds: process.env['RPC_CACHE_MILLISECONDS'] || '1000',
knownBaker: process.env['TEZOS_BAKER'] || 'tz1cjyja1TU6fiyiFav3mFAdnDsCReJ12hPD',
Expand Down Expand Up @@ -157,7 +157,7 @@ const kathmandunetSecretKey = {
};

const limanetSecretKey = {
rpc: process.env['TEZOS_RPC_LIMANET'] || 'https://limanet-archive.ecadinfra.com',
rpc: process.env['TEZOS_RPC_LIMANET'] || 'http://ecad-limanet-full:8732',
pollingIntervalMilliseconds: process.env['POLLING_INTERVAL_MILLISECONDS'] || undefined,
rpcCacheMilliseconds: process.env['RPC_CACHE_MILLISECONDS'] || '1000',
knownBaker: process.env['TEZOS_BAKER'] || 'tz1cjyja1TU6fiyiFav3mFAdnDsCReJ12hPD',
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/contract-estimation-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, protocol, rpc }) =>
expect(estimate.minimalFeeMutez).toEqual(651);
expect(estimate.totalCost).toEqual(651);
expect(estimate.usingBaseFeeMutez).toEqual(651);
expect(estimate.consumedMilligas).toEqual(3148528);
expect(estimate.consumedMilligas).toEqual(3148700);
done();
})

Expand Down Expand Up @@ -198,7 +198,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, protocol, rpc }) =>
expect(estimate.minimalFeeMutez).toEqual(811);
expect(estimate.totalCost).toEqual(129311);
expect(estimate.usingBaseFeeMutez).toEqual(811);
expect(estimate.consumedMilligas).toEqual(4156198);
expect(estimate.consumedMilligas).toEqual(4156370);
done();
})

Expand Down Expand Up @@ -230,7 +230,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, protocol, rpc }) =>
expect(estimate.minimalFeeMutez).toEqual(698);
expect(estimate.totalCost).toEqual(79948);
expect(estimate.usingBaseFeeMutez).toEqual(698);
expect(estimate.consumedMilligas).toEqual(3559038);
expect(estimate.consumedMilligas).toEqual(3559210);
done();
})

Expand Down Expand Up @@ -258,7 +258,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, protocol, rpc }) =>
expect(estimate.minimalFeeMutez).toEqual(905);
expect(estimate.totalCost).toEqual(159405);
expect(estimate.usingBaseFeeMutez).toEqual(905);
expect(estimate.consumedMilligas).toEqual(4977218);
expect(estimate.consumedMilligas).toEqual(4977390);
// Do the actual operation
const op2 = await contract.methods.do(originate2()).send();
await op2.confirmation();
Expand Down
119 changes: 108 additions & 11 deletions integration-tests/contract-increase-paid-storage-operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,95 @@ import { CONFIGS } from './config';
import { OpKind, Protocols } from '@taquito/taquito';
import { ligoSample } from './data/ligo-simple-contract';

CONFIGS().forEach(({ lib, rpc, setup, protocol, knownContract }) => {
const kathmandunetAndAlpha = (protocol === Protocols.PtKathman || protocol === Protocols.ProtoALpha) ? test : test.skip;
CONFIGS().forEach(({ lib, rpc, setup, protocol }) => {
const kathmandunet = (protocol === Protocols.PtKathman) ? test : test.skip;
const limanetAndAlpha = (protocol === Protocols.PtLimaPtL || protocol === Protocols.ProtoALpha) ? test : test.skip;

const Tezos = lib;

let simpleContractAddress: string;
describe(`Test Increase Paid Storage using: ${rpc}`, () => {
beforeEach(async (done) => {
beforeAll(async (done) => {
await setup(true);

try {
const op = await Tezos.contract.originate({
balance: "1",
code: `parameter string;
storage string;
code {CAR;
PUSH string "Hello ";
CONCAT;
NIL operation; PAIR};
`,
init: `"test"`
});

await op.confirmation();

simpleContractAddress = op.contractAddress!;
} catch(e) {
console.log(JSON.stringify(e));
}
done();
});

kathmandunetAndAlpha('should be able to increase the paid storage of a contract successfully', async (done) => {
kathmandunet(`should be able to increase the paid storage of a contract successfully: ${rpc}`, async (done) => {
const op = await Tezos.contract.increasePaidStorage({
amount: 1,
destination: knownContract
destination: simpleContractAddress
});

await op.confirmation();
expect(op.hash).toBeDefined();
expect(op.status).toEqual('applied');
done();
});

limanetAndAlpha(`should be able to increase the paid storage of a contract successfully: ${rpc}`, async (done) => {
const paidSpaceBefore = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

const op = await Tezos.contract.increasePaidStorage({
amount: 1,
destination: simpleContractAddress
});

await op.confirmation();
expect(op.hash).toBeDefined();
expect(op.status).toEqual('applied');

const paidSpaceAfter = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

expect(parseInt(paidSpaceAfter)).toEqual(parseInt(paidSpaceBefore) + 1);
done();
});

kathmandunet(`should be able to include increasePaidStorage operation in a batch: ${rpc}`, async (done) => {
const op = await Tezos.contract
.batch()
.withOrigination({
balance: "1",
code: `parameter string;
storage string;
code {CAR;
PUSH string "Hello ";
CONCAT;
NIL operation; PAIR};
`,
init: `"test"`
})
.withIncreasePaidStorage({
amount: 1,
destination: simpleContractAddress
})
.send();
await op.confirmation();
expect(op.status).toEqual('applied');
done();
});

kathmandunetAndAlpha('should be able to include increasePaidStorage operation in a batch', async (done) => {
limanetAndAlpha(`should be able to include increasePaidStorage operation in a batch: ${rpc}`, async (done) => {
const paidSpaceBefore = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

const op = await Tezos.contract
.batch()
.withOrigination({
Expand All @@ -40,15 +106,42 @@ CONFIGS().forEach(({ lib, rpc, setup, protocol, knownContract }) => {
})
.withIncreasePaidStorage({
amount: 1,
destination: knownContract
destination: simpleContractAddress
})
.send();
await op.confirmation();
expect(op.status).toEqual('applied');

const paidSpaceAfter = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

expect(parseInt(paidSpaceAfter)).toEqual(parseInt(paidSpaceBefore) + 1);
done();
});

kathmandunet(`should be able to include increasePaidStorage operation in a batch (different batch syntax): ${rpc}`, async (done) => {
const op = await Tezos.contract.batch([
{
kind: OpKind.ORIGINATION,
balance: '1',
code: ligoSample,
storage: 0
},
{
kind: OpKind.INCREASE_PAID_STORAGE,
amount: 1,
destination: simpleContractAddress
}
])
.send();

await op.confirmation();
expect(op.status).toEqual('applied');
done();
});

kathmandunetAndAlpha('should be able to include increasePaidStorage operation in a batch (different batch syntax)', async (done) => {
limanetAndAlpha(`should be able to include increasePaidStorage operation in a batch (different batch syntax): ${rpc}`, async (done) => {
const paidSpaceBefore = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

const op = await Tezos.contract.batch([
{
kind: OpKind.ORIGINATION,
Expand All @@ -59,17 +152,21 @@ CONFIGS().forEach(({ lib, rpc, setup, protocol, knownContract }) => {
{
kind: OpKind.INCREASE_PAID_STORAGE,
amount: 1,
destination: knownContract
destination: simpleContractAddress
}
])
.send();

await op.confirmation();
expect(op.status).toEqual('applied');

const paidSpaceAfter = await Tezos.rpc.getStoragePaidSpace(simpleContractAddress);

expect(parseInt(paidSpaceAfter)).toEqual(parseInt(paidSpaceBefore) + 1);
done();
});

kathmandunetAndAlpha('should return error when destination contract address is invalid', async (done) => {
it('should return error when destination contract address is invalid', async (done) => {
expect(async () => {
const op = await Tezos.contract.increasePaidStorage({
amount: 1,
Expand Down
28 changes: 28 additions & 0 deletions integration-tests/rpc-nodes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CONFIGS } from './config';
import { Protocols } from "@taquito/taquito";
import { RpcClientCache, RpcClient, RPCRunViewParam, RPCRunScriptViewParam } from '@taquito/rpc';
import { encodeExpr } from '@taquito/utils';
import { Schema } from '@taquito/michelson-encoder';
Expand All @@ -19,6 +20,9 @@ CONFIGS().forEach(
}) => {
const Tezos = lib;

const limanetAndAlpha = protocol === Protocols.PtLimaPtL || protocol === Protocols.ProtoALpha ? test : test.skip;
const kathmandunetAndAlpha = protocol === Protocols.PtKathman || protocol === Protocols.ProtoALpha ? test : test.skip;

beforeAll(async (done) => {
await setup()
done()
Expand Down Expand Up @@ -416,6 +420,30 @@ CONFIGS().forEach(
expect(state).toBeDefined();
done();
});

kathmandunetAndAlpha('Verify that rpcClient.getTxRollupInbox will access the inbox of a transaction rollup', async (done) => {
const inbox = await rpcClient.getTxRollupInbox(txRollupAddress, '0');
expect(inbox).toBeDefined();
done();
});

kathmandunetAndAlpha('Verify that rpcClient.getTxRollupState will access the state of a rollup', async (done) => {
const state = await rpcClient.getTxRollupState(txRollupAddress);
expect(state).toBeDefined();
done();
});

limanetAndAlpha('Verify that rpcClient.getStorageUsedSpace will retrieve the used space of a contract storage', async (done) => {
const usedSpace = await rpcClient.getStorageUsedSpace(knownContract);
expect(usedSpace).toBeDefined();
done();
});

limanetAndAlpha('Verify that rpcClient.getStoragePaidSpace will retrieve the paid space of a contract storage', async (done) => {
const paidSpace = await rpcClient.getStoragePaidSpace(knownContract);
expect(paidSpace).toBeDefined();
done();
});
});
});
}
Expand Down
12 changes: 12 additions & 0 deletions packages/taquito-contracts-library/src/rpc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,16 @@ export class RpcWrapperContractsLibrary implements RpcClientInterface {
): Promise<TxRollupInboxResponse | null> {
return this.rpc.getTxRollupInbox(txRollupId, blockLevel, { block });
}
async getStorageUsedSpace(
contract: string,
{ block }: RPCOptions = defaultRPCOptions
): Promise<string> {
return this.rpc.getStorageUsedSpace(contract, { block });
}
async getStoragePaidSpace(
contract: string,
{ block }: RPCOptions = defaultRPCOptions
): Promise<string> {
return this.rpc.getStoragePaidSpace(contract, { block });
}
}
4 changes: 4 additions & 0 deletions packages/taquito-rpc/src/rpc-client-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface RpcClientInterface {
blockLevel: string,
options?: RPCOptions
): Promise<TxRollupInboxResponse | null>;
getStorageUsedSpace(contract: string, options?: RPCOptions): Promise<string>;
getStoragePaidSpace(contract: string, options?: RPCOptions): Promise<string>;
}

export enum RPCMethodName {
Expand Down Expand Up @@ -155,4 +157,6 @@ export enum RPCMethodName {
GET_TX_ROLLUP_STATE = 'getTxRollupState',
GET_VOTES_LISTINGS = 'getVotesListings',
PACK_DATA = 'packData',
GET_STORAGE_USED_SPACE = 'getStorageUsedSpace',
GET_STORAGE_PAID_SPACE = 'getStoragePaidSpace',
}
54 changes: 54 additions & 0 deletions packages/taquito-rpc/src/rpc-client-modules/rpc-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,4 +1111,58 @@ export class RpcClientCache implements RpcClientInterface {
return response;
}
}

/**
*
* @param contract address of the contract we want to retrieve storage information of
* @param options contains generic configuration for rpc calls
*
* @description Access the amount of used space used in a contract's storage
*
* @see https://tezos.gitlab.io/lima/rpc.html#get-block-id-context-contracts-contract-id-storage
*/
async getStorageUsedSpace(
contract: string,
{ block }: { block: string } = defaultRPCOptions
): Promise<string> {
const key = this.formatCacheKey(
this.rpcClient.getRpcUrl(),
RPCMethodName.GET_STORAGE_USED_SPACE,
[block, contract]
);
if (this.has(key)) {
return this.get(key);
} else {
const response = this.rpcClient.getStorageUsedSpace(contract, { block });
this.put(key, response);
return response;
}
}

/**
*
* @param contract address of the contract we want to retrieve storage information of
* @param options contains generic configuration for rpc calls
*
* @description Access the amount of paid space in a contract's storage
*
* @see https://tezos.gitlab.io/lima/rpc.html#get-block-id-context-contracts-contract-id-storage
*/
async getStoragePaidSpace(
contract: string,
{ block }: { block: string } = defaultRPCOptions
): Promise<string> {
const key = this.formatCacheKey(
this.rpcClient.getRpcUrl(),
RPCMethodName.GET_STORAGE_PAID_SPACE,
[block, contract]
);
if (this.has(key)) {
return this.get(key);
} else {
const response = this.rpcClient.getStoragePaidSpace(contract, { block });
this.put(key, response);
return response;
}
}
}
Loading

0 comments on commit 7e5a1b8

Please sign in to comment.