Skip to content

Commit

Permalink
rpc: remove hardcoded data in test
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Jul 19, 2024
1 parent 517c2d9 commit 58aedb2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rpc/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,20 @@ func TestNotify(t *testing.T) {
msg := &types.Header{
ParentHash: common.HexToHash("0x01"),
Number: big.NewInt(100),
Difficulty: common.Big0,
}
notifier.Notify(id, msg)
have := strings.TrimSpace(out.String())
want := `{"jsonrpc":"2.0","method":"_subscription","params":{"subscription":"test","result":{"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000001","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","difficulty":null,"number":"0x64","gasLimit":"0x0","gasUsed":"0x0","timestamp":"0x0","extraData":"0x","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","baseFeePerGas":null,"withdrawalsRoot":null,"blobGasUsed":null,"excessBlobGas":null,"parentBeaconBlockRoot":null,"hash":"0xe5fb877dde471b45b9742bb4bb4b3d74a761e2fb7cb849a3d2b687eed90fb604"}}}`
if have != want {

type Response struct {
Params struct {
Result types.Header
}
}
var resp Response
if err := json.Unmarshal(out.Bytes(), &resp); err != nil {
t.Errorf("failed to unmarshal response: %v", err)
}
if have, want := resp.Params.Result.Hash(), msg.Hash(); have != want {
t.Errorf("have:\n%v\nwant:\n%v\n", have, want)
}
}

0 comments on commit 58aedb2

Please sign in to comment.