-
Notifications
You must be signed in to change notification settings - Fork 20
/
NotFoundMessageTests.swift
55 lines (47 loc) · 1.92 KB
/
NotFoundMessageTests.swift
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
//
// NotFoundMessageTests.swift
// BitcoinSwift
//
// Created by James MacWhyte on 9/27/14.
// Copyright (c) 2014 DoubleSha. All rights reserved.
//
import BitcoinSwift
import XCTest
class NotFoundMessageTests: XCTestCase {
let notFoundMessageBytes: [UInt8] = [
0x01, // Number of inventory vectors (1)
0x02, 0x00, 0x00, 0x00, // First vector type (2: Block)
0x71, 0x40, 0x03, 0x91, 0x50, 0x8c, 0xae, 0x45,
0x35, 0x86, 0x4f, 0x74, 0x91, 0x76, 0xab, 0x7f,
0xa3, 0xa2, 0x51, 0xc2, 0x13, 0x40, 0x21, 0x1e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] // Block hash
var notFoundMessageData: NSData!
var notFoundMessage: NotFoundMessage!
override func setUp() {
super.setUp()
let vector0HashBytes: [UInt8] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1e, 0x21, 0x40, 0x13, 0xc2, 0x51, 0xa2, 0xa3,
0x7f, 0xab, 0x76, 0x91, 0x74, 0x4f, 0x86, 0x35,
0x45, 0xae, 0x8c, 0x50, 0x91, 0x03, 0x40, 0x71] // Block hash
let vector0Hash = SHA256Hash(bytes: vector0HashBytes)
let inventoryVectors = [InventoryVector(type: .Block, hash: vector0Hash)]
notFoundMessage = NotFoundMessage(inventoryVectors: inventoryVectors)
notFoundMessageData = NSData(bytes: notFoundMessageBytes, length: notFoundMessageBytes.count)
}
// TODO: Add edge test cases: Too many vectors, empty data, etc.
func testNotFoundMessageEncoding() {
XCTAssertEqual(notFoundMessage.bitcoinData, notFoundMessageData)
}
func testNotFoundMessageDecoding() {
let stream = NSInputStream(data: notFoundMessageData)
stream.open()
if let testNotFoundMessage = NotFoundMessage.fromBitcoinStream(stream) {
XCTAssertEqual(testNotFoundMessage, notFoundMessage)
} else {
XCTFail("Failed to parse NotFoundMessage")
}
XCTAssertFalse(stream.hasBytesAvailable)
stream.close()
}
}