-
Notifications
You must be signed in to change notification settings - Fork 7
/
vm.test.ts
89 lines (77 loc) · 2.55 KB
/
vm.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { IActiveDSConnect } from "../packages/definitions/lib/definitions";
import { VirtualMachine } from "../packages/protocol/src/protocol/vm";
import { ActiveCrypto } from "../packages/crypto/src";
import { expect, should } from "chai";
import "mocha";
describe("Virtual Machine Test (Activeprotocol)", () => {
// Some Random Test Data
const random = Math.floor(Math.random() * 100000000 + 1);
let VM: VirtualMachine;
it("should create secured VM", () => {
VM = new VirtualMachine(
"localhost:5259",
new ActiveCrypto.Secured({} as IActiveDSConnect, [], {}) as any, // Fix private type
{} as any,
{} as any
);
expect(VM).to.be.an("object");
});
it("should initalise VM contract as promised", () => {
expect(
VM.initialise(
{
contractLocation: "./test/",
umid: "test",
date: new Date(),
remoteAddress: "localhost",
transaction: {
$namespace: "test",
$contract: "test",
$i: {},
$o: {}
},
signatures: {
testStreamId:
"mJbmGI2VdTMC6u+/mQroEPe4unnIVtTr9W85NGsrEAi5jCG4Kt3X+yGMMYQ79wEzTyFpkcyIKHpXDfiRZLInP1BiI5ukdjI+rRNbelK0ueGLh9rHElkxm3znwxRt1ZQeXaFzUtmdLtvo1jhxxZeEa3Hs9AmvTCKWx96KJKaSaREokY3UARZZZzTKIHR5rTL4nrjd8v2g+/hWMzcm1XugjfDNqBRST8J0LYXlyvFnLOE/fc40P8JI3FKDXy/aWHS5sH9CoJDP3kYho/07Tfo4/H0jZGrJ0YQ15kc6ZUonxYRlGNpO+kpsWjhksAKVmgNMsho1nEf7d39i0Dn3aKG/Tg==",
$sig: ""
},
inputs: [],
outputs: [],
readonly: {},
key: random
},
"test"
)
).to.be.a("promise");
});
it("should run smart contract verify as promised", () => {
expect(VM.verify(true, "test")).to.be.a("promise");
});
it("should run smart contract vote as promised", () => {
expect(VM.vote("test")).to.be.a("promise");
});
it("should run smart contract commit as promised", () => {
expect(VM.commit({} as any, false, "test")).to.be.a("promise");
});
it("should get transaction inputs from VM", () => {
expect(VM.getInputs("test"))
.to.be.an("array")
.length(0);
});
it("should get error as no valid contract loaded to retrieve from", () => {
// Transaction
should().throw(() => {
VM.getThrowsFromVM();
});
// Activity Streams
should().throw(() => {
VM.getActivityStreamsFromVM();
});
// Node Comms
should().throw(() => {
VM.getInternodeCommsFromVM();
});
// Prevent timeout checks
(VM as any).scriptFinishedExec = true;
});
});