chore: a test for interactionType check
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user