2021-09-10 19:21:45 +03:00
|
|
|
import { Fluence, FluencePeer } from '../../index';
|
2021-09-08 12:42:30 +03:00
|
|
|
import { RequestFlowBuilder } from '../../internal/RequestFlowBuilder';
|
|
|
|
|
2021-09-10 19:21:45 +03:00
|
|
|
const anotherPeer = new FluencePeer();
|
2021-09-08 12:42:30 +03:00
|
|
|
|
|
|
|
describe('Avm spec', () => {
|
|
|
|
afterEach(async () => {
|
2021-09-10 19:21:45 +03:00
|
|
|
if (anotherPeer) {
|
|
|
|
await anotherPeer.stop();
|
2021-09-08 12:42:30 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Par execution should work', async () => {
|
|
|
|
// arrange
|
2021-09-10 19:21:45 +03:00
|
|
|
await Fluence.start();
|
2021-09-08 12:42:30 +03:00
|
|
|
|
|
|
|
let request;
|
|
|
|
const promise = new Promise<string[]>((resolve) => {
|
|
|
|
let res = [];
|
|
|
|
request = new RequestFlowBuilder()
|
|
|
|
.withRawScript(
|
|
|
|
`
|
|
|
|
(seq
|
|
|
|
(par
|
|
|
|
(call %init_peer_id% ("print" "print") ["1"])
|
|
|
|
(null)
|
|
|
|
)
|
|
|
|
(call %init_peer_id% ("print" "print") ["2"])
|
|
|
|
)
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
.configHandler((h) => {
|
|
|
|
h.onEvent('print', 'print', async (args) => {
|
|
|
|
res.push(args[0]);
|
|
|
|
if (res.length == 2) {
|
|
|
|
resolve(res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
});
|
|
|
|
|
|
|
|
// act
|
2021-09-10 19:21:45 +03:00
|
|
|
await Fluence.getPeer().internals.initiateFlow(request);
|
2021-09-08 12:42:30 +03:00
|
|
|
const res = await promise;
|
|
|
|
|
|
|
|
// assert
|
|
|
|
expect(res).toStrictEqual(['1', '2']);
|
|
|
|
});
|
|
|
|
});
|