forked from decentraland/decentraland-rpc
/
7.0.MethodsInjection.ts
40 lines (29 loc) 路 1.18 KB
/
7.0.MethodsInjection.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
import * as assert from 'assert'
import { shouldFail, TestableScript } from './support/ClientHelpers'
import { Methods } from './support/ClientCommons'
import { inject } from '../../lib/client/index'
export default class TestMethods extends TestableScript {
@inject() Methods: Methods | null = null
async doTest() {
if (!this.Methods) {
throw new Error('Methods was not loaded')
}
const Methods = this.Methods
assert.equal(await Methods.enable(), 1)
assert.equal(typeof await Methods.getRandomNumber(), 'number')
assert((await Methods.getRandomNumber()) > 0)
const sentObject = {
x: await Methods.getRandomNumber()
}
assert.deepEqual(await Methods.receiveObject(sentObject), {
received: sentObject
})
await Methods.failsWithoutParams(1)
await Methods.failsWithParams()
await shouldFail(() => Methods.failsWithoutParams(), 'failsWithoutParams')
await shouldFail(() => Methods.failsWithParams(1), 'failsWithParams')
const sentElements = [1, true, null, false, 'xxx', { a: null }]
assert.deepEqual(await Methods.bounce(...sentElements), sentElements)
console.log('If you see this console.log, it did work')
}
}