Skip to content

Commit

Permalink
futures factory permissions test
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Mar 29, 2024
1 parent 75dd968 commit 38ce151
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/components/futures/factory_add_account.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ chai.use(chaiAsPromised);
chai.use(chaiSubset);
const { expect } = chai;

describe(`[${process.pid}] grid_trading: add account`, () => {
describe(`[${process.pid}] futures: add account`, () => {
let accounts;
let assetId1;
let assetId2;
Expand Down
222 changes: 222 additions & 0 deletions test/components/futures/factory_permissions.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { invokeScript } from '@waves/waves-transactions';
import {
chainId, broadcast,
} from '../../utils/api.mjs';
import { setup } from './_setup.mjs';

chai.use(chaiAsPromised);
const { expect } = chai;

describe(`[${process.pid}] futures: factory permissions`, () => {
let accounts;

before(async () => {
({
accounts,
} = await setup());
});

it('stringEntry', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'stringEntry',
args: [
{ type: 'string', value: 'test' },
{ type: 'string', value: 'test' },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('integerEntry', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'integerEntry',
args: [
{ type: 'string', value: 'test' },
{ type: 'integer', value: 0 },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('booleanEntry', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'booleanEntry',
args: [
{ type: 'string', value: 'test' },
{ type: 'boolean', value: true },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('binaryEntry', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'binaryEntry',
args: [
{ type: 'string', value: 'test' },
{ type: 'binary', value: [] },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('deleteEntry', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'deleteEntry',
args: [
{ type: 'string', value: 'test' },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('reissue', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'reissue',
args: [
{ type: 'binary', value: [] },
{ type: 'integer', value: 0 },
{ type: 'boolean', value: true },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('burn', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'burn',
args: [
{ type: 'binary', value: [] },
{ type: 'integer', value: 0 },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('transferAsset', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'transferAsset',
args: [
{ type: 'binary', value: [] },
{ type: 'integer', value: 0 },
{ type: 'binary', value: [] },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('transferAssets', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'transferAssets',
args: [
{ type: 'binary', value: [] },
{ type: 'list', value: [] },
{ type: 'list', value: [] },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('transferWaves', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'transferWaves',
args: [
{ type: 'binary', value: [] },
{ type: 'integer', value: 0 },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.calculator.seed)).to.be.fulfilled;
});

it('init', async () => {
const fn = async (caller) => broadcast(invokeScript({
dApp: accounts.factory.address,
call: {
function: 'init',
args: [
{ type: 'string', value: '' },
{ type: 'string', value: '' },
{ type: 'binary', value: [] },
{ type: 'integer', value: 0 },
],
},
payment: [],
chainId,
}, caller));

expect(fn(accounts.user1.seed)).to.be.rejectedWith('permission denied');
expect(fn(accounts.factory.seed)).to.be.fulfilled;
});
});
2 changes: 1 addition & 1 deletion test/components/futures/factory_request_account.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chai.use(chaiAsPromised);
chai.use(chaiSubset);
const { expect } = chai;

describe(`[${process.pid}] grid_trading: factory request account`, () => {
describe(`[${process.pid}] futures: factory request account`, () => {
let accounts;
let rewardAmount;
let assetId1;
Expand Down

0 comments on commit 38ce151

Please sign in to comment.