Skip to content

Commit

Permalink
test: implement unit tests for stake, unstake, and finalizeUnstake
Browse files Browse the repository at this point in the history
  • Loading branch information
ac10n committed Sep 26, 2023
1 parent 4a940e3 commit 12f55f1
Show file tree
Hide file tree
Showing 2 changed files with 330 additions and 0 deletions.
97 changes: 97 additions & 0 deletions packages/taquito/test/estimate/rpc-estimate-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,4 +1588,101 @@ describe('RPCEstimateProvider test wallet', () => {
done();
});
});

describe('stake', () => {
it('return the correct estimate for stake', async (done) => {
mockRpcClient.simulateOperation.mockResolvedValue({
contents: [
{
kind: 'transaction',
fee: 10017,
metadata: {
operation_result: { status: 'applied', consumed_milligas: '10013000' },
},
parameters: {
entrypoint: 'stake',
value: {
prim: 'Unit',
},
},
},
],
});
// Simulate real op size
mockForger.forge.mockResolvedValue(new Array(149).fill('aa').join(''));
const estimate = await estimateProvider.stake({
amount: 10000,
});
expect(estimate).toMatchObject({
gasLimit: 10113,
storageLimit: 0,
suggestedFeeMutez: 1361,
});
done();
});
});

describe('unstake', () => {
it('return the correct estimate for unstake', async (done) => {
mockRpcClient.simulateOperation.mockResolvedValue({
contents: [
{
kind: 'transaction',
fee: 10018,
metadata: {
operation_result: { status: 'applied', consumed_milligas: '10014000' },
},
parameters: {
entrypoint: 'unstake',
value: {
prim: 'Unit',
},
},
},
],
});
// Simulate real op size
mockForger.forge.mockResolvedValue(new Array(149).fill('aa').join(''));
const estimate = await estimateProvider.unstake({
amount: 10000,
});
expect(estimate).toMatchObject({
gasLimit: 10114,
storageLimit: 0,
suggestedFeeMutez: 1361,
});
done();
});
});

describe('finalizeUnstake', () => {
it('return the correct estimate for finalizeUnstake', async (done) => {
mockRpcClient.simulateOperation.mockResolvedValue({
contents: [
{
kind: 'transaction',
fee: 10018,
metadata: {
operation_result: { status: 'applied', consumed_milligas: '10014000' },
},
parameters: {
entrypoint: 'finalize_unstake',
value: {
prim: 'Unit',
},
},
},
],
});
// Simulate real op size
mockForger.forge.mockResolvedValue(new Array(149).fill('aa').join(''));
const estimate = await estimateProvider.finalizeUnstake({});
expect(estimate).toMatchObject({
gasLimit: 10114,
storageLimit: 0,
suggestedFeeMutez: 1361,
});
done();
});
});
});
233 changes: 233 additions & 0 deletions packages/taquito/test/prepare/prepare-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,4 +1114,237 @@ describe('PrepareProvider test', () => {
done();
});
});

describe('stake', () => {
it('should return a prepared stake operation with reveal operation', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(false);

const prepared = await prepareProvider.stake({
amount: 10000,
});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
kind: 'reveal',
fee: '374',
public_key: 'test_pub_key',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
gas_limit: '1100',
storage_limit: '0',
counter: '1',
},
{
amount: '10000000000',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '2',
parameters: {
entrypoint: 'stake',
value: {
prim: 'Unit',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});

it('should return a prepared stake op without reveal operation when account is revealed', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(true);

const prepared = await prepareProvider.stake({
amount: 10000,
});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
amount: '10000000000',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '1',
parameters: {
entrypoint: 'stake',
value: {
prim: 'Unit',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});
});

describe('unstake', () => {
it('should return a prepared unstake operation with reveal operation', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(false);

const prepared = await prepareProvider.unstake({
amount: 10000,
});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
kind: 'reveal',
fee: '374',
public_key: 'test_pub_key',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
gas_limit: '1100',
storage_limit: '0',
counter: '1',
},
{
amount: '0',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '2',
parameters: {
entrypoint: 'unstake',
value: {
int: '10000000000',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});

it('should return a prepared unstake op without reveal operation when account is revealed', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(true);

const prepared = await prepareProvider.unstake({
amount: 10000,
});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
amount: '0',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '1',
parameters: {
entrypoint: 'unstake',
value: {
int: '10000000000',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});
});

describe('finalizeUnstake', () => {
it('should return a prepared finalize_unstake operation with reveal operation', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(false);

const prepared = await prepareProvider.finalizeUnstake({});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
kind: 'reveal',
fee: '374',
public_key: 'test_pub_key',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
gas_limit: '1100',
storage_limit: '0',
counter: '1',
},
{
amount: '0',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '2',
parameters: {
entrypoint: 'finalize_unstake',
value: {
prim: 'Unit',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});

it('should return a prepared finalize_unstake op without reveal operation when account is revealed', async () => {
mockReadProvider.isAccountRevealed.mockResolvedValue(true);

const prepared = await prepareProvider.finalizeUnstake({});

expect(prepared).toEqual({
opOb: {
branch: 'test_block_hash',
contents: [
{
amount: '0',
kind: 'transaction',
source: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
fee: '0',
gas_limit: '1040000',
storage_limit: '60000',
destination: 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM',
counter: '1',
parameters: {
entrypoint: 'finalize_unstake',
value: {
prim: 'Unit',
},
},
},
],
protocol: 'test_protocol',
},
counter: 0,
});
});
});
});

0 comments on commit 12f55f1

Please sign in to comment.