Skip to content

Commit

Permalink
Add test vectors for ping extensions (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML authored Jan 20, 2025
1 parent 975a35e commit 5b879ec
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 29 deletions.
2 changes: 2 additions & 0 deletions ping-payload-extensions/extensions/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Pong Message = Container(
payload: [Payload]
)
```

## Test Vectors
63 changes: 62 additions & 1 deletion ping-payload-extensions/extensions/type-0.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Client Info and Capabilities Payload

## Client Info
Client info are ASCII hex encoded strings.
Client info are UTF-8 hex encoded strings.

Client info strings consist of 4 parts
- client name (e.x. `trin`,`fluffy`)
Expand Down Expand Up @@ -42,3 +42,64 @@ Ping/Pong Message = Container(
)
```

## Test Vectors

### Protocol Message to ssz encoded ping: case 1 with client info

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
client_info = "trin/v0.1.1-b61fdc5c/linux-x86_64/rustc1.81.0"
capabilities = [0, 1, 65535]
```

#### Expected Output
```
message = 0x00010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff550000007472696e2f76302e312e312d62363166646335632f6c696e75782d7838365f36342f7275737463312e38312e3000000100ffff
```

### Protocol Message to ssz encoded ping: case 2 without client info

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
client_info = ""
capabilities = [0, 1, 65535]
```

#### Expected Output
```
message = 0x00010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2800000000000100ffff
```

### Protocol Message to ssz encoded pong: case 1 with client info

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
client_info = "trin/v0.1.1-b61fdc5c/linux-x86_64/rustc1.81.0"
capabilities = [0, 1, 65535]
```

#### Expected Output
```
message = 0x01010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff550000007472696e2f76302e312e312d62363166646335632f6c696e75782d7838365f36342f7275737463312e38312e3000000100ffff
```

### Protocol Message to ssz encoded pong: case 2 without client info

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
client_info = ""
capabilities = [0, 1, 65535]
```

#### Expected Output
```
message = 0x01010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2800000000000100ffff
```
27 changes: 27 additions & 0 deletions ping-payload-extensions/extensions/type-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,30 @@ Ping/Pong Message = Container(
)
```

## Test Vectors

### Protocol Message to ssz encoded ping

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
```

#### Expected Output
```
message = 0x00010000000000000001000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
```

### Protocol Message to ssz encoded pong

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
```

#### Expected Output
```
message = 0x01010000000000000001000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
```
30 changes: 30 additions & 0 deletions ping-payload-extensions/extensions/type-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,33 @@ Ping/Pong Message = Container(
payload: history_radius
)
```

## Test Vectors

### Protocol Message to ssz encoded ping

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
ephemeral_header_count = 4242
```

#### Expected Output
```
message = 0x00010000000000000002000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9210
```

### Protocol Message to ssz encoded pong

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
ephemeral_header_count = 4242
```

#### Expected Output
```
message = 0x01010000000000000002000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9210
```
20 changes: 18 additions & 2 deletions ping-payload-extensions/extensions/type-65535.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ If the ping receiver can't handle the ping for any reason the pong should return
Pong payload
```python

# Max ASCII hex encoded strings length
# Max UTF-8 hex encoded strings length
MAX_ERROR_BYTE_LENGTH = 300

error_payload = SSZ.serialize(Container(error_code: u16, message: ByteList[MAX_ERROR_BYTE_LENGTH]))
Expand All @@ -31,4 +31,20 @@ This error code should be used when a client is unable to provide the necessary
Wasn't able to decode the payload

#### 3: System error
A critical error happened and the ping can't be processed
A critical error happened and the ping can't be processed

## Test Vectors

### Protocol Message to ssz encoded pong

#### Input Parameters
```
enr_seq = 1
error_code = 2
message = "hello world"
```

#### Expected Output
```
message = 0x010100000000000000ffff0e00000002000600000068656c6c6f20776f726c64
```
28 changes: 2 additions & 26 deletions portal-wire-test-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,9 @@ This section provides test vectors for the individual protocol messages defined
in the [Portal wire protocol](./portal-wire-protocol.md). These test vectors can
primarily verify the SSZ encoding and decoding of each protocol message.

### Ping Request
### Ping Request and Pong Response

#### Input Parameters
```
enr_seq = 1
data_radius = 2^256 - 2 # Maximum value - 1
custom_payload = serialize(Container(data_radius))
```

#### Expected Output
```
message = 0x0001000000000000000c000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
```

### Pong Response

#### Input Parameters
```
enr_seq = 1
data_radius = (2^256 - 1) / 2 # Maximum value / 2
custom_payload = serialize(Container(data_radius))
```

#### Expected Output
```
message = 0x0101000000000000000c000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f
```
These test vectors are located in the specifications for each [ping extension type](./ping-payload-extensions/extensions/)

### Find Nodes Request

Expand Down

0 comments on commit 5b879ec

Please sign in to comment.