chore: a test for interactionType check

This commit is contained in:
ppedziwiatr
2023-12-27 15:10:59 +01:00
parent 5015a3f0b4
commit 01d69d811b
2 changed files with 19 additions and 0 deletions

View File

@@ -118,6 +118,20 @@ describe('Testing the Profit Sharing Token', () => {
expect(resultVM.target).toEqual('uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M');
});
// note that this requires a check inside contract code!
it('should not eval interaction that calls view function', async () => {
const interaction = await pst.writeInteraction({
function: 'balance'
});
await mineBlock(warp);
const result = await pst.readState();
expect(result.cachedValue.validity[interaction.originalTxId]).toBeFalsy();
expect(result.cachedValue.errorMessages[interaction.originalTxId]).toContain('Trying to call "view" function from a "write" action');
});
it('should properly dispatch an event', async () => {
let handlerCalled = false;
const interactionResult = await pst.writeInteraction({

View File

@@ -3,6 +3,7 @@ export async function handle(state, action) {
const canEvolve = state.canEvolve;
const input = action.input;
const caller = action.caller;
const interactionType = action.interactionType;
if (input.function === 'transfer') {
const target = input.target;
@@ -66,6 +67,10 @@ export async function handle(state, action) {
}
if (input.function === 'balance') {
if (interactionType !== 'view') {
throw new ContractError('Trying to call "view" function from a "write" action.');
}
const target = input.target;
const ticker = state.ticker;