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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! Constants holding raw Monero data.

//---------------------------------------------------------------------------------------------------- Import

//---------------------------------------------------------------------------------------------------- Block
/// Generate a `const _: &[u8]` pointing to a block blob.
///
/// This will deserialize with `Block` to assume the blob is at least deserializable.
///
/// This requires some static block input for testing.
///
/// The actual block blob data on disk is found in `data/block`.
///
/// See below for actual usage.
macro_rules! const_block_blob {
    (
        name: $name:ident, // Name of the `const` created
        height: $height:literal, // Block height
        hash: $hash:literal, // Block hash
        data_path: $data_path:literal, // Path to the block blob
        major_version: $major_version:literal, // Block's major version
        minor_version: $minor_version:literal, // Block's minor version
        timestamp: $timestamp:literal, // Block's timestamp
        nonce: $nonce:literal, // Block's nonce
        tx_len: $tx_len:literal, // How many transactions there are in the block
    ) => {
        #[doc = concat!("Block with hash `", $hash, "`.")]
        ///
        #[doc = concat!("Height: `", $height, "`.")]
        ///
        /// ```rust
        #[doc = "# use cuprate_test_utils::data::*;"]
        #[doc = "use monero_serai::{block::Block, transaction::Input};"]
        #[doc = ""]
        #[doc = concat!("let block = Block::read(&mut ", stringify!($name), ").unwrap();")]
        #[doc = ""]
        #[doc = concat!("assert_eq!(block.header.hardfork_version, ", $major_version, ");")]
        #[doc = concat!("assert_eq!(block.header.hardfork_signal, ", $minor_version, ");")]
        #[doc = concat!("assert_eq!(block.header.timestamp, ", $timestamp, ");")]
        #[doc = concat!("assert_eq!(block.header.nonce, ", $nonce, ");")]
        #[doc = concat!("assert!(matches!(block.miner_transaction.prefix().inputs[0], Input::Gen(", $height, ")));")]
        #[doc = concat!("assert_eq!(block.transactions.len(), ", $tx_len, ");")]
        #[doc = concat!("assert_eq!(hex::encode(block.hash()), \"", $hash, "\")")]
        /// ```
        pub const $name: &[u8] = include_bytes!($data_path);
    };
}

const_block_blob! {
    name: BLOCK_BBD604,
    height: 202_612,
    hash: "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698",
    data_path: "block/bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698.bin",
    major_version: 1,
    minor_version: 0,
    timestamp: 1409804570,
    nonce: 1073744198,
    tx_len: 513,
}

const_block_blob! {
    name: BLOCK_5ECB7E,
    height: 202_609,
    hash: "5ecb7e663bbe947c734c8059e7d7d52dc7d6644bb82d81a6ad4057d127ee8eda",
    data_path: "block/5ecb7e663bbe947c734c8059e7d7d52dc7d6644bb82d81a6ad4057d127ee8eda.bin",
    major_version: 1,
    minor_version: 0,
    timestamp: 1409804315,
    nonce: 48426,
    tx_len: 2,
}

const_block_blob! {
    name: BLOCK_F91043,
    height: 1_731_606,
    hash: "f910435a5477ca27be1986c080d5476aeab52d0c07cf3d9c72513213350d25d4",
    data_path: "block/f910435a5477ca27be1986c080d5476aeab52d0c07cf3d9c72513213350d25d4.bin",
    major_version: 9,
    minor_version: 9,
    timestamp: 1545423190,
    nonce: 4123173351,
    tx_len: 3,
}

const_block_blob! {
    name: BLOCK_43BD1F,
    height: 2_751_506,
    hash: "43bd1f2b6556dcafa413d8372974af59e4e8f37dbf74dc6b2a9b7212d0577428",
    data_path: "block/43bd1f2b6556dcafa413d8372974af59e4e8f37dbf74dc6b2a9b7212d0577428.bin",
    major_version: 16,
    minor_version: 16,
    timestamp: 1667941829,
    nonce: 4110909056,
    tx_len: 0,
}

//---------------------------------------------------------------------------------------------------- Transaction
/// Generate a `const _: &[u8]` pointing to a transaction blob.
///
/// Same as [`const_block_blob`] but for transactions.
macro_rules! const_tx_blob {
    (
        name: $name:ident, // Name of the `const` created
        hash: $hash:literal, // Transaction hash
        data_path: $data_path:literal, // Path to the transaction blob
        version: $version:literal, // Transaction version
        timelock: $timelock:expr, // Transaction's timelock (use the real type `Timelock`)
        input_len: $input_len:literal, // Amount of inputs
        output_len: $output_len:literal, // Amount of outputs
    ) => {
        #[doc = concat!("Transaction with hash `", $hash, "`.")]
        ///
        /// ```rust
        #[doc = "# use cuprate_test_utils::data::*;"]
        #[doc = "use monero_serai::transaction::{Transaction, Timelock};"]
        #[doc = ""]
        #[doc = concat!("let tx = Transaction::read(&mut ", stringify!($name), ").unwrap();")]
        #[doc = ""]
        #[doc = concat!("assert_eq!(tx.version(), ", $version, ");")]
        #[doc = concat!("assert_eq!(tx.prefix().additional_timelock, ", stringify!($timelock), ");")]
        #[doc = concat!("assert_eq!(tx.prefix().inputs.len(), ", $input_len, ");")]
        #[doc = concat!("assert_eq!(tx.prefix().outputs.len(), ", $output_len, ");")]
        #[doc = concat!("assert_eq!(hex::encode(tx.hash()), \"", $hash, "\")")]
        /// ```
        pub const $name: &[u8] = include_bytes!($data_path);
    };
}

const_tx_blob! {
    name: TX_3BC7FF,
    hash: "3bc7ff015b227e7313cc2e8668bfbb3f3acbee274a9c201d6211cf681b5f6bb1",
    data_path: "tx/3bc7ff015b227e7313cc2e8668bfbb3f3acbee274a9c201d6211cf681b5f6bb1.bin",
    version: 1,
    timelock: Timelock::Block(100_081),
    input_len: 1,
    output_len: 5,
}

const_tx_blob! {
    name: TX_2180A8,
    hash: "2180a87f724702d37af087e22476297e818a73579ef7b7da947da963245202a3",
    data_path: "tx/2180a87f724702d37af087e22476297e818a73579ef7b7da947da963245202a3.bin",
    version: 1,
    timelock: Timelock::None,
    input_len: 19,
    output_len: 61,
}

const_tx_blob! {
    name: TX_D7FEBD,
    hash: "d7febd16293799d9c6a8e0fe9199b8a0a3e0da5a8a165098937b60f0bbd582df",
    data_path: "tx/d7febd16293799d9c6a8e0fe9199b8a0a3e0da5a8a165098937b60f0bbd582df.bin",
    version: 1,
    timelock: Timelock::None,
    input_len: 46,
    output_len: 46,
}

const_tx_blob! {
    name: TX_E2D393,
    hash: "e2d39395dd1625b2d707b98af789e7eab9d24c2bd2978ec38ef910961a8cdcee",
    data_path: "tx/e2d39395dd1625b2d707b98af789e7eab9d24c2bd2978ec38ef910961a8cdcee.bin",
    version: 2,
    timelock: Timelock::None,
    input_len: 1,
    output_len: 2,
}

const_tx_blob! {
    name: TX_E57440,
    hash: "e57440ec66d2f3b2a5fa2081af40128868973e7c021bb3877290db3066317474",
    data_path: "tx/e57440ec66d2f3b2a5fa2081af40128868973e7c021bb3877290db3066317474.bin",
    version: 2,
    timelock: Timelock::None,
    input_len: 1,
    output_len: 2,
}

const_tx_blob! {
    name: TX_B6B439,
    hash: "b6b4394d4ec5f08ad63267c07962550064caa8d225dd9ad6d739ebf60291c169",
    data_path: "tx/b6b4394d4ec5f08ad63267c07962550064caa8d225dd9ad6d739ebf60291c169.bin",
    version: 2,
    timelock: Timelock::None,
    input_len: 2,
    output_len: 2,
}

const_tx_blob! {
    name: TX_9E3F73,
    hash: "9e3f73e66d7c7293af59c59c1ff5d6aae047289f49e5884c66caaf4aea49fb34",
    data_path: "tx/9e3f73e66d7c7293af59c59c1ff5d6aae047289f49e5884c66caaf4aea49fb34.bin",
    version: 1,
    timelock: Timelock::None,
    input_len: 2,
    output_len: 5,
}

const_tx_blob! {
    name: TX_84D48D,
    hash: "84d48dc11ec91950f8b70a85af9db91fe0c8abef71ef5db08304f7344b99ea66",
    data_path: "tx/84d48dc11ec91950f8b70a85af9db91fe0c8abef71ef5db08304f7344b99ea66.bin",
    version: 2,
    timelock: Timelock::None,
    input_len: 2,
    output_len: 2,
}

//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {}