Skip to content

Commit 27b3c90

Browse files
author
ScottyPoi
committed
test ClientInfo functions
1 parent 4edb1cf commit 27b3c90

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { assert, describe, expect, it } from 'vitest'
2+
import { decodeClientInfo, encodeClientInfo } from '../../src/index.js'
3+
import { bytesToHex, hexToBytes, toAscii } from '@ethereumjs/util'
4+
describe('Client Info', () => {
5+
const testVectors = {
6+
object: {
7+
clientName: 'trin',
8+
clientVersionAndShortCommit: '0.1.1-2b00d730',
9+
operatingSystemAndCpuArchitecture: 'linux-x86_64',
10+
programmingLanguageAndVersion: 'rustc1.81.0',
11+
},
12+
string: 'trin/0.1.1-2b00d730/linux-x86_64/rustc1.81.0',
13+
hex: '0x7472696E2F302E312E312D32623030643733302F6C696E75782D7838365F36342F7275737463312E38312E30',
14+
}
15+
16+
it('should encode client info hex', () => {
17+
const encoded = encodeClientInfo(testVectors.object)
18+
expect(bytesToHex(encoded).toLowerCase()).toEqual(testVectors.hex.toLowerCase())
19+
})
20+
21+
it('should decode client info hex', () => {
22+
const decoded = decodeClientInfo(hexToBytes(testVectors.hex))
23+
assert.deepEqual(decoded, testVectors.object)
24+
})
25+
26+
it('should equal client info string', () => {
27+
assert.equal(toAscii(testVectors.hex), testVectors.string)
28+
})
29+
})

0 commit comments

Comments
 (0)