/
transactions.parity.test.ts
163 lines (128 loc) · 5.08 KB
/
transactions.parity.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import gql from 'graphql-tag'
import utilDev, { TestClient } from '@cardano-graphql/util-dev'
import { buildSchema } from '@src/index'
import { getDataFromAPI } from './getDataFromApi'
describe('transactions', () => {
let client: TestClient
let restData: any
let graphQLData: any
beforeAll(async () => {
if (process.env.TEST_MODE === 'e2e') {
client = await utilDev.createE2EClient()
} else {
const schema = await buildSchema('http://localhost:8090')
client = await utilDev.createIntegrationClient(schema)
}
const restResult = await getDataFromAPI('txs/summary/1ac36644733c367ee4c551413d799d2e395d6ddfe14bebf1c281e6e826901762')
restData = restResult.Right
const graphQLResult = await client.query({
query: gql`query TxByHash{
transactions (where: {hash: {_eq:"1ac36644733c367ee4c551413d799d2e395d6ddfe14bebf1c281e6e826901762"}})
{
hash
fee
block{
number
forgedAt
}
inputs(order_by: { sourceTxHash: asc }) {
address
value
sourceTxHash
sourceTxIndex
}
outputs(order_by: { index: asc }) {
address
index
value
}
totalOutput
includedAt
}
}`
})
graphQLData = graphQLResult.data.transactions[0]
}, 30000)
it('return the correct hash', async () => {
const restResultId = restData.ctsId
const graphQLHash = graphQLData.hash
expect(graphQLHash).toEqual(restResultId)
})
it('return the correct Result Fee', async () => {
const restResultFee = restData.ctsFees.getCoin
const graphQLFee = graphQLData.fee
expect(graphQLFee).toEqual(parseInt(restResultFee))
})
it('return the correct Total Output', async () => {
const restResultTotalOutput = restData.ctsTotalOutput.getCoin
const graphQLTotalOutput = graphQLData.totalOutput
expect(graphQLTotalOutput).toEqual(restResultTotalOutput)
})
it('return the correct Block Height', async () => {
const restResultTotalOutput = restData.ctsBlockHeight
const graphQLTotalOutput = graphQLData.block.number
expect(graphQLTotalOutput).toEqual(restResultTotalOutput)
})
it('return the correct Input Addresses', async () => {
const restResultInputs = restData.ctsInputs
const restResultAddresses = []
for (const input of restResultInputs) {
restResultAddresses.push(input[0])
}
const graphQLInputs = graphQLData.inputs
const graphQLAddresses = []
for (const input of graphQLInputs) {
graphQLAddresses.push(input.address)
}
expect(graphQLAddresses).toEqual(restResultAddresses)
})
it('return the correct Input Values', async () => {
const restResultInputs = restData.ctsInputs
let restResultValues = 0
for (const input of restResultInputs) {
restResultValues += Number(input[1].getCoin)
}
const graphQLInputs = graphQLData.inputs
let graphQLValues = 0
for (const input of graphQLInputs) {
graphQLValues += Number(input.value)
}
expect(graphQLValues).toEqual(restResultValues)
})
it('return the correct Output Addresses', async () => {
const restResultOutputs = restData.ctsOutputs
const restResultAddresses = []
for (const output of restResultOutputs) {
restResultAddresses.push(output[0])
}
const graphQLOutputs = graphQLData.outputs
const graphQLAddresses = []
for (const output of graphQLOutputs) {
graphQLAddresses.push(output.address)
}
expect(graphQLAddresses).toEqual(restResultAddresses)
})
it('return the correct Output Values', async () => {
const restResultOutputs = restData.ctsOutputs
let restResultValues = 0
for (const output of restResultOutputs) {
restResultValues += Number(output[1].getCoin)
}
const graphQLOutputs = graphQLData.outputs
let graphQLValues = 0
for (const output of graphQLOutputs) {
graphQLValues += Number(output.value)
}
expect(graphQLValues).toEqual(restResultValues)
})
it('have the same block creation time', async () => {
const restResultBlockTime = restData.ctsBlockTimeIssued
const graphQLBlockTime = graphQLData.block.forgedAt
expect(graphQLBlockTime).toEqual(utilDev.timestampToIsoStringWithoutTimezone(restResultBlockTime))
})
it('have the same transaction inclusion time', async () => {
const restResultTransactionTime = restData.ctsTxTimeIssued
const graphQLTransactionTime = graphQLData.includedAt
expect(graphQLTransactionTime).toEqual(utilDev.timestampToIsoStringWithoutTimezone(restResultTransactionTime))
})
})