1
+ import { bytesToHex } from '@ethereumjs/util'
1
2
import { beforeAll , describe , expect , test } from 'vitest'
2
3
3
- import { ContextWrapper } from '../verkleFFIBindings/index'
4
+ import { Context } from '../verkleFFIBindings/index'
4
5
5
6
describe ( 'bindings' , ( ) => {
6
- let context : ContextWrapper
7
+ let context : Context
7
8
beforeAll ( ( ) => {
8
- context = ContextWrapper . _default ( )
9
+ context = Context . _default ( )
9
10
} )
10
11
11
12
test ( 'getTreeKey' , ( ) => {
@@ -27,9 +28,9 @@ describe('bindings', () => {
27
28
const sub_index = 0
28
29
29
30
const key = context . getTreeKey ( address , tree_index_le , sub_index )
30
- const key_hex = Buffer . from ( key ) . toString ( 'hex' )
31
+ const key_hex = bytesToHex ( key )
31
32
32
- const expected = '76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a700273700 '
33
+ const expected = '0x76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a700273700 '
33
34
34
35
expect ( key_hex ) . toBe ( expected )
35
36
} )
@@ -44,9 +45,9 @@ describe('bindings', () => {
44
45
const scalars = [ scalar , scalar ]
45
46
const commitment = context . commitToScalars ( scalars )
46
47
47
- const commitment_hex = Buffer . from ( commitment ) . toString ( 'hex' )
48
+ const commitment_hex = bytesToHex ( commitment )
48
49
const expected =
49
- '6fb3421d850da8e8b8d1b9c1cc30876ef23d9df72c8792e6d569a9861089f02abdf89e2c671fe0bff820e815f6f20453fdbc83ec5415e3ade8c745179e31d25c '
50
+ '0x6fb3421d850da8e8b8d1b9c1cc30876ef23d9df72c8792e6d569a9861089f02abdf89e2c671fe0bff820e815f6f20453fdbc83ec5415e3ade8c745179e31d25c '
50
51
51
52
expect ( commitment_hex ) . toBe ( expected )
52
53
} )
@@ -60,9 +61,9 @@ describe('bindings', () => {
60
61
const commitment = context . commitToScalars ( [ scalar ] )
61
62
62
63
const commitmentHash = context . hashCommitment ( commitment )
63
- const commitmentHashHex = Buffer . from ( commitmentHash ) . toString ( 'hex' )
64
+ const commitmentHashHex = bytesToHex ( commitmentHash )
64
65
65
- const expected = '31e94bef2c0160ed1f3dd9caacbed356939c2e440c4ddb336d832dcab6384e19 '
66
+ const expected = '0x31e94bef2c0160ed1f3dd9caacbed356939c2e440c4ddb336d832dcab6384e19 '
66
67
67
68
expect ( commitmentHashHex ) . toBe ( expected )
68
69
} )
@@ -80,9 +81,9 @@ describe('bindings', () => {
80
81
81
82
for ( let i = 0 ; i < hashes . length ; i ++ ) {
82
83
const expectedHash = context . hashCommitment ( commitments [ i ] )
83
- const expectedHashHex = Buffer . from ( expectedHash ) . toString ( 'hex' )
84
+ const expectedHashHex = bytesToHex ( expectedHash )
84
85
85
- const commitmentHashHex = Buffer . from ( hashes [ i ] ) . toString ( 'hex' )
86
+ const commitmentHashHex = bytesToHex ( hashes [ i ] )
86
87
87
88
expect ( commitmentHashHex ) . toBe ( expectedHashHex )
88
89
}
@@ -97,9 +98,9 @@ describe('bindings', () => {
97
98
const commitment = context . commitToScalars ( [ scalar ] )
98
99
99
100
const commitmentHash = context . deprecateSerializeCommitment ( commitment )
100
- const commitmentHashHex = Buffer . from ( commitmentHash ) . toString ( 'hex' )
101
+ const commitmentHashHex = bytesToHex ( commitmentHash )
101
102
102
- const expected = '6d40cf3d3097cb19b0ff686a068d53fb1250cc98bbd33766cf2cce00acb8b0a6 '
103
+ const expected = '0x6d40cf3d3097cb19b0ff686a068d53fb1250cc98bbd33766cf2cce00acb8b0a6 '
103
104
104
105
expect ( commitmentHashHex ) . toBe ( expected )
105
106
} )
@@ -120,15 +121,15 @@ describe('bindings', () => {
120
121
] )
121
122
122
123
const expected = context . scalarMulIndex ( newScalarValue , commitmentIndex )
123
- const expectedHex = Buffer . from ( expected ) . toString ( 'hex' )
124
+ const expectedHex = bytesToHex ( expected )
124
125
125
126
const updatedCommitment = context . updateCommitment (
126
127
commitment ,
127
128
commitmentIndex ,
128
129
oldScalarValue ,
129
130
newScalarValue ,
130
131
)
131
- const updatedCommitmentHex = Buffer . from ( updatedCommitment ) . toString ( 'hex' )
132
+ const updatedCommitmentHex = bytesToHex ( updatedCommitment )
132
133
133
134
expect ( updatedCommitmentHex ) . toBe ( expectedHex )
134
135
} )
0 commit comments