forked from smartcontractkit/external-adapters-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack.test.ts
91 lines (85 loc) · 2.28 KB
/
pack.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
90
91
import * as create from '../../src/methods/createMarkets'
import * as resolve from '../../src/methods/resolveMarkets'
describe('packCreation', () => {
const requests = [
{
name: 'empty data',
testData: {
eventId: '0',
homeTeamId: 0,
awayTeamId: 0,
startTime: 0,
homeSpread: 0,
totalScore: 0,
createSpread: false,
createTotalScore: false,
},
expect: '0x0000000000000000000000000000000000000000000000000000000000000000',
},
{
name: 'realistic data',
testData: {
eventId: '9a35b8986a76eaaea364be331cb453ec',
homeTeamId: 2929,
awayTeamId: 2928,
startTime: Date.parse('2020-02-02T23:30:00Z'),
homeSpread: -4.499,
totalScore: 53,
createSpread: true,
createTotalScore: true,
},
expect: '0x9a35b8986a76eaaea364be331cb453ec0b710b705e375b78ffd3021203000000',
},
]
requests.forEach((req) => {
it(`${req.name}`, async () => {
const p = req.testData
const got = create.packCreation(
p.eventId,
p.homeTeamId,
p.awayTeamId,
p.startTime,
p.homeSpread,
p.totalScore,
p.createSpread,
p.createTotalScore,
)
expect(got).toEqual(req.expect)
const bytes = Buffer.from(got.substr(2), 'hex').byteLength
expect(bytes).toBe(32)
})
})
})
describe('packResolution', () => {
const requests = [
{
name: 'empty data',
testData: {
eventId: '0',
eventStatus: 0,
homeScore: 0,
awayScore: 0,
},
expect: '0x0000000000000000000000000000000000000000000000000000000000000000',
},
{
name: 'realistic data',
testData: {
eventId: '9a35b8986a76eaaea364be331cb453ec',
eventStatus: 2,
homeScore: 31,
awayScore: 20,
},
expect: '0x9a35b8986a76eaaea364be331cb453ec02013600c80000000000000000000000',
},
]
requests.forEach((req) => {
it(`${req.name}`, async () => {
const p = req.testData
const got = resolve.packResolution(p.eventId, p.eventStatus, p.homeScore, p.awayScore)
expect(got).toEqual(req.expect)
const bytes = Buffer.from(got.substr(2), 'hex').byteLength
expect(bytes).toBe(32)
})
})
})