Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2850 migration test #2938

Merged
merged 7 commits into from
Apr 29, 2024
39 changes: 39 additions & 0 deletions integration-tests/__tests__/pseudo-entrypoints-forging.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { CONFIGS } from "../config";
import { DefaultContractType, UnitValue } from "@taquito/taquito";
import { LocalForger, ProtocolsHash } from '@taquito/local-forging'

CONFIGS().forEach(({ rpc, protocol, setup, lib }) => {
const Tezos = lib;

describe(`Test forging pseudo entrypoints: ${rpc}`, () => {
let contract: DefaultContractType
// for every new protocol need to check https://tezos.gitlab.io/shell/p2p_api.html#alpha-entrypoint-determined-from-data-8-bit-tag for the latest entrypoints and corresponding tag
let entrypoint = { 0: 'default', 1: 'root', 2: 'do', 3: 'set_delegate', 4: 'remove_delegate', 5: 'deposit', 6: 'stake', 7: 'unstake', 8: 'finalize_unstake', 9: 'set_delegate_parameters' }

beforeAll(async () => {
await setup();
try {
// for every new entrypoint will need to modify the contract code to have new entrypoint covered
let op = await Tezos.contract.originate({
code: [{ "prim": "parameter", "args": [{ "prim": "or", "args": [{ "prim": "unit", "annots": ["%default"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%root"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%do"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%set_delegate"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%remove_delegate"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%deposit"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%stake"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%unstake"] }, { "prim": "or", "args": [{ "prim": "unit", "annots": ["%finalize_unstake"] }, { "prim": "unit", "annots": ["%set_delegate_parameters"] }] }] }] }] }] }] }] }] }] }] }, { "prim": "storage", "args": [{ "prim": "string" }] }, { "prim": "code", "args": [[{ "prim": "CAR" }, { "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "default" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "root" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "do" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "set_delegate" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "remove_delegate" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "deposit" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "stake" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "unstake" }] }], [{ "prim": "IF_LEFT", "args": [[{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "finalize_unstake" }] }], [{ "prim": "DROP" }, { "prim": "PUSH", "args": [{ "prim": "string" }, { "string": "set_delegate_parameters" }] }]] }]] }]] }]] }]] }]] }]] }]] }]] }, { "prim": "NIL", "args": [{ "prim": "operation" }] }, { "prim": "PAIR" }]] }],
storage: 'init'
})
await op.confirmation();
contract = await op.contract();
} catch(e) {console.log(e)}
})

Object.values(entrypoint).forEach(name => {
it(`Verify that local forge will return same result as for rpc forge for entrypoints name ${name}`, async () => {
const localForger = new LocalForger(protocol as unknown as ProtocolsHash);
const methodObject = await contract.methodsObject[name](UnitValue)
const prepared = await Tezos.prepare.contractCall(methodObject)
const operation = Tezos.prepare.toForge(prepared)
const result = await localForger.forge(operation);
const rpcResult = await Tezos.rpc.forgeOperations(operation);
expect(result).toEqual(rpcResult);
});
})

});
});
Loading