|
13 | 13 | // See the License for the specific language governing permissions and |
14 | 14 | // limitations under the License. |
15 | 15 |
|
16 | | -// Here we have some definitions that are used by other tests, as well as tests |
17 | | -// that check those definitions (if needed). |
| 16 | +// Here we have some general definitions that are used by other tests. |
18 | 17 |
|
19 | 18 | import { |
20 | | - Amount, |
21 | | - Network, |
22 | 19 | make_private_key, |
23 | 20 | public_key_from_private_key, |
24 | | - make_default_account_privkey, |
25 | | - make_receiving_address, |
26 | | - pubkey_to_pubkeyhash_address, |
27 | | - encode_input_for_utxo, |
28 | | - encode_input_for_withdraw_from_delegation, |
29 | | - encode_lock_until_height, |
30 | | - encode_output_lock_then_transfer, |
31 | | - encode_output_create_stake_pool, |
32 | | - encode_stake_pool_data, |
33 | 21 | } from "../../pkg/wasm_wrappers.js"; |
34 | 22 |
|
35 | | -import { |
36 | | - TEXT_ENCODER, |
37 | | - assert_eq_arrays, |
38 | | - get_err_msg, |
39 | | -} from "./utils.js"; |
40 | | - |
41 | 23 | // Taken from TESTNET_FORK_HEIGHT_5_ORDERS_V1 in common/src/chain/config/builder.rs. |
42 | 24 | // This will be updated to the actual height after we choose one. |
43 | 25 | export const ORDERS_V1_TESTNET_FORK_HEIGHT = 999_999_999; |
@@ -71,131 +53,6 @@ export const get_predefined_pub_key = (function () { |
71 | 53 | } |
72 | 54 | })(); |
73 | 55 |
|
74 | | -// Some address. |
75 | | -// It corresponds to `make_receiving_address(make_default_account_privkey(MNEMONIC,Network.Testnet), 0)`, |
76 | | -// but most tests don't care. |
77 | | -export const ADDRESS = "tmt1q9dn5m4svn8sds3fcy09kpxrefnu75xekgr5wa3n"; |
78 | | - |
79 | 56 | // Some token id. |
80 | 57 | export const TOKEN_ID = |
81 | 58 | "tmltk15tgfrs49rv88v8utcllqh0nvpaqtgvn26vdxhuner5m6ewg9c3msn9fxns"; |
82 | | - |
83 | | -// Some test inputs - a UTXO and a delegation withdrawal |
84 | | -export const INPUTS = [ |
85 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
86 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
87 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, |
88 | | -]; |
89 | | - |
90 | | -// OutpointSourceId used in INPUTS. |
91 | | -export const TX_OUTPOINT = new Uint8Array(33).fill(0) |
92 | | - |
93 | | -export const OUTPUT_LOCK_THEN_TRANSFER = [ |
94 | | - 1, 0, 145, 1, 1, 91, 58, 110, 176, 100, 207, 6, 194, 41, 193, 30, 91, 4, |
95 | | - 195, 202, 103, 207, 80, 217, 178, 0, 145, 1 |
96 | | -]; |
97 | | - |
98 | | -export const OUTPUT_CREATE_STAKE_POOL = [ |
99 | | - 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
100 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, |
101 | | - 113, 2, 0, 1, 91, 58, 110, 176, 100, 207, 6, 194, 41, 193, 30, 91, 4, 195, |
102 | | - 202, 103, 207, 80, 217, 178, 0, 108, 245, 234, 97, 170, 9, 247, 158, 169, |
103 | | - 100, 84, 123, 235, 183, 147, 29, 136, 118, 203, 24, 146, 56, 60, 217, 2, |
104 | | - 198, 32, 133, 255, 240, 84, 123, 1, 91, 58, 110, 176, 100, 207, 6, 194, |
105 | | - 41, 193, 30, 91, 4, 195, 202, 103, 207, 80, 217, 178, 100, 0, 0, |
106 | | -]; |
107 | | - |
108 | | -// Some tx outputs - LockThenTransfer and CreateStakePool |
109 | | -export const OUTPUTS = [...OUTPUT_LOCK_THEN_TRANSFER, ...OUTPUT_CREATE_STAKE_POOL]; |
110 | | - |
111 | | -export async function test_predefined_address() { |
112 | | - const account_private_key = make_default_account_privkey( |
113 | | - MNEMONIC, |
114 | | - Network.Testnet |
115 | | - ); |
116 | | - console.log(`acc private key = ${account_private_key}`); |
117 | | - |
118 | | - const receiving_privkey = make_receiving_address(account_private_key, 0); |
119 | | - console.log(`receiving privkey = ${receiving_privkey}`); |
120 | | - |
121 | | - const receiving_pubkey = public_key_from_private_key(receiving_privkey); |
122 | | - const address = pubkey_to_pubkeyhash_address( |
123 | | - receiving_pubkey, |
124 | | - Network.Testnet |
125 | | - ); |
126 | | - console.log(`address = ${address}`); |
127 | | - if (address != ADDRESS) { |
128 | | - throw new Error("Incorrect address generated"); |
129 | | - } |
130 | | -} |
131 | | - |
132 | | -export async function test_encode_predefined_inputs() { |
133 | | - const tx_input = encode_input_for_utxo(TX_OUTPOINT, 1); |
134 | | - const deleg_id = |
135 | | - "mdelg1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqut3aj8"; |
136 | | - const tx_input2 = encode_input_for_withdraw_from_delegation( |
137 | | - deleg_id, |
138 | | - Amount.from_atoms("1"), |
139 | | - BigInt(1), |
140 | | - Network.Mainnet |
141 | | - ); |
142 | | - const inputs = [...tx_input, ...tx_input2]; |
143 | | - assert_eq_arrays(inputs, INPUTS); |
144 | | -} |
145 | | - |
146 | | -export async function test_encode_predefined_outputs() { |
147 | | - const vrf_public_key = |
148 | | - "tvrfpk1qpk0t6np4gyl084fv328h6ahjvwcsaktrzfrs0xeqtrzpp0l7p28knrnn57"; |
149 | | - |
150 | | - const pool_data = encode_stake_pool_data( |
151 | | - Amount.from_atoms("40000"), |
152 | | - ADDRESS, |
153 | | - vrf_public_key, |
154 | | - ADDRESS, |
155 | | - 100, |
156 | | - Amount.from_atoms("0"), |
157 | | - Network.Testnet |
158 | | - ); |
159 | | - const expected_pool_data = [ |
160 | | - 2, 113, 2, 0, 1, 91, 58, 110, 176, 100, 207, 6, 194, 41, 193, 30, 91, 4, |
161 | | - 195, 202, 103, 207, 80, 217, 178, 0, 108, 245, 234, 97, 170, 9, 247, 158, |
162 | | - 169, 100, 84, 123, 235, 183, 147, 29, 136, 118, 203, 24, 146, 56, 60, 217, |
163 | | - 2, 198, 32, 133, 255, 240, 84, 123, 1, 91, 58, 110, 176, 100, 207, 6, 194, |
164 | | - 41, 193, 30, 91, 4, 195, 202, 103, 207, 80, 217, 178, 100, 0, 0, |
165 | | - ]; |
166 | | - |
167 | | - assert_eq_arrays(pool_data, expected_pool_data); |
168 | | - |
169 | | - const lock = encode_lock_until_height(BigInt(100)); |
170 | | - const output = encode_output_lock_then_transfer( |
171 | | - Amount.from_atoms("100"), |
172 | | - ADDRESS, |
173 | | - lock, |
174 | | - Network.Testnet |
175 | | - ); |
176 | | - |
177 | | - const pool_id = |
178 | | - "tpool1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqza035u"; |
179 | | - try { |
180 | | - const invalid_pool_data = TEXT_ENCODER.encode("invalid pool data"); |
181 | | - encode_output_create_stake_pool( |
182 | | - pool_id, |
183 | | - invalid_pool_data, |
184 | | - Network.Testnet |
185 | | - ); |
186 | | - throw new Error("Invalid pool data worked somehow!"); |
187 | | - } catch (e) { |
188 | | - if (!get_err_msg(e).includes("Invalid stake pool data encoding")) { |
189 | | - throw e; |
190 | | - } |
191 | | - console.log("Tested invalid pool data successfully"); |
192 | | - } |
193 | | - const stake_pool_output = encode_output_create_stake_pool( |
194 | | - pool_id, |
195 | | - pool_data, |
196 | | - Network.Testnet |
197 | | - ); |
198 | | - const outputs = [...output, ...stake_pool_output]; |
199 | | - |
200 | | - assert_eq_arrays(outputs, OUTPUTS); |
201 | | -} |
0 commit comments