mirror of
https://github.com/alexgo-io/brc20-indexer-contracts.git
synced 2026-01-12 22:21:46 +08:00
test: indexer (#24)
* test: indexer can hash, validate and index * test: indexer can hash, validate and index * bitcoin block and proof * test * test updated
This commit is contained in:
committed by
GitHub
parent
d187d24209
commit
4998b7d3a2
@@ -20,6 +20,7 @@
|
||||
"bignumber.js": "^9.1.2",
|
||||
"bitcoinjs-lib": "^6.1.3",
|
||||
"clarity-codegen": "^0.2.6",
|
||||
"electrum-client-sl": "^0.1.4",
|
||||
"got-cjs": "^12.5.4",
|
||||
"lodash": "^4.17.21",
|
||||
"micro-btc-signer": "^0.4.2",
|
||||
|
||||
135
pnpm-lock.yaml
generated
135
pnpm-lock.yaml
generated
@@ -1,9 +1,5 @@
|
||||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
'@iarna/toml':
|
||||
specifier: ^2.2.5
|
||||
@@ -32,6 +28,9 @@ dependencies:
|
||||
clarity-codegen:
|
||||
specifier: ^0.2.6
|
||||
version: 0.2.6(@stacks/transactions@6.7.0)
|
||||
electrum-client-sl:
|
||||
specifier: ^0.1.4
|
||||
version: 0.1.4
|
||||
got-cjs:
|
||||
specifier: ^12.5.4
|
||||
version: 12.5.4
|
||||
@@ -944,6 +943,14 @@ packages:
|
||||
ieee754: 1.2.1
|
||||
dev: false
|
||||
|
||||
/bufferutil@4.0.7:
|
||||
resolution: {integrity: sha512-kukuqc39WOHtdxtw4UScxF/WVnMFVSQVKhtx3AjZJzhd0RGZZldcrfSEbVsWWe6KNH253574cq5F+wpv0G9pJw==}
|
||||
engines: {node: '>=6.14.2'}
|
||||
requiresBuild: true
|
||||
dependencies:
|
||||
node-gyp-build: 4.6.1
|
||||
dev: false
|
||||
|
||||
/c32check@1.1.3:
|
||||
resolution: {integrity: sha512-ADADE/PjAbJRlwpG3ShaOMbBUlJJZO7xaYSRD5Tub6PixQlgR4s36y9cvMf/YRGpkqX+QOxIdMw216iC320q9A==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -1074,6 +1081,24 @@ packages:
|
||||
buffer: 5.7.1
|
||||
dev: false
|
||||
|
||||
/d@1.0.1:
|
||||
resolution: {integrity: sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==}
|
||||
dependencies:
|
||||
es5-ext: 0.10.62
|
||||
type: 1.2.0
|
||||
dev: false
|
||||
|
||||
/debug@2.6.9:
|
||||
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.0.0
|
||||
dev: false
|
||||
|
||||
/decode-uri-component@0.2.2:
|
||||
resolution: {integrity: sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==}
|
||||
engines: {node: '>=0.10'}
|
||||
@@ -1107,6 +1132,15 @@ packages:
|
||||
safe-buffer: 5.2.1
|
||||
dev: false
|
||||
|
||||
/electrum-client-sl@0.1.4:
|
||||
resolution: {integrity: sha512-tnBNbMvIJ6uCglby93i0JIOfWyr7Ch/MYXtCX4X4me+axS85fBwX8L4AKhLRslaAw4fUwnL0IE8fdLPhKABKQQ==}
|
||||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
websocket: 1.0.34
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/elliptic@6.5.4:
|
||||
resolution: {integrity: sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==}
|
||||
dependencies:
|
||||
@@ -1129,6 +1163,31 @@ packages:
|
||||
once: 1.4.0
|
||||
dev: false
|
||||
|
||||
/es5-ext@0.10.62:
|
||||
resolution: {integrity: sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==}
|
||||
engines: {node: '>=0.10'}
|
||||
requiresBuild: true
|
||||
dependencies:
|
||||
es6-iterator: 2.0.3
|
||||
es6-symbol: 3.1.3
|
||||
next-tick: 1.1.0
|
||||
dev: false
|
||||
|
||||
/es6-iterator@2.0.3:
|
||||
resolution: {integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==}
|
||||
dependencies:
|
||||
d: 1.0.1
|
||||
es5-ext: 0.10.62
|
||||
es6-symbol: 3.1.3
|
||||
dev: false
|
||||
|
||||
/es6-symbol@3.1.3:
|
||||
resolution: {integrity: sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==}
|
||||
dependencies:
|
||||
d: 1.0.1
|
||||
ext: 1.7.0
|
||||
dev: false
|
||||
|
||||
/esbuild@0.18.20:
|
||||
resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==}
|
||||
engines: {node: '>=12'}
|
||||
@@ -1164,6 +1223,12 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/ext@1.7.0:
|
||||
resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==}
|
||||
dependencies:
|
||||
type: 2.7.2
|
||||
dev: false
|
||||
|
||||
/file-uri-to-path@1.0.0:
|
||||
resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==}
|
||||
dev: false
|
||||
@@ -1308,6 +1373,10 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: false
|
||||
|
||||
/is-typedarray@1.0.0:
|
||||
resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==}
|
||||
dev: false
|
||||
|
||||
/json-buffer@3.0.1:
|
||||
resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==}
|
||||
dev: false
|
||||
@@ -1424,10 +1493,18 @@ packages:
|
||||
iced-runtime: 1.0.4
|
||||
dev: false
|
||||
|
||||
/ms@2.0.0:
|
||||
resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==}
|
||||
dev: false
|
||||
|
||||
/nan@2.17.0:
|
||||
resolution: {integrity: sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==}
|
||||
dev: false
|
||||
|
||||
/next-tick@1.1.0:
|
||||
resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==}
|
||||
dev: false
|
||||
|
||||
/node-fetch@2.7.0:
|
||||
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
@@ -1440,6 +1517,11 @@ packages:
|
||||
whatwg-url: 5.0.0
|
||||
dev: false
|
||||
|
||||
/node-gyp-build@4.6.1:
|
||||
resolution: {integrity: sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/normalize-url@6.1.0:
|
||||
resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -1699,6 +1781,20 @@ packages:
|
||||
fsevents: 2.3.3
|
||||
dev: false
|
||||
|
||||
/type@1.2.0:
|
||||
resolution: {integrity: sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==}
|
||||
dev: false
|
||||
|
||||
/type@2.7.2:
|
||||
resolution: {integrity: sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==}
|
||||
dev: false
|
||||
|
||||
/typedarray-to-buffer@3.1.5:
|
||||
resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==}
|
||||
dependencies:
|
||||
is-typedarray: 1.0.0
|
||||
dev: false
|
||||
|
||||
/typeforce@1.18.0:
|
||||
resolution: {integrity: sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==}
|
||||
dev: false
|
||||
@@ -1715,6 +1811,14 @@ packages:
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/utf-8-validate@5.0.10:
|
||||
resolution: {integrity: sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==}
|
||||
engines: {node: '>=6.14.2'}
|
||||
requiresBuild: true
|
||||
dependencies:
|
||||
node-gyp-build: 4.6.1
|
||||
dev: false
|
||||
|
||||
/util-deprecate@1.0.2:
|
||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||
dev: false
|
||||
@@ -1733,6 +1837,20 @@ packages:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: false
|
||||
|
||||
/websocket@1.0.34:
|
||||
resolution: {integrity: sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
dependencies:
|
||||
bufferutil: 4.0.7
|
||||
debug: 2.6.9
|
||||
es5-ext: 0.10.62
|
||||
typedarray-to-buffer: 3.1.5
|
||||
utf-8-validate: 5.0.10
|
||||
yaeti: 0.0.6
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/whatwg-url@5.0.0:
|
||||
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
|
||||
dependencies:
|
||||
@@ -1764,6 +1882,11 @@ packages:
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/yaeti@0.0.6:
|
||||
resolution: {integrity: sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==}
|
||||
engines: {node: '>=0.10.32'}
|
||||
dev: false
|
||||
|
||||
/yargs-parser@21.1.1:
|
||||
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
|
||||
engines: {node: '>=12'}
|
||||
@@ -1795,3 +1918,7 @@ packages:
|
||||
resolution: {integrity: sha512-6tE3PSRcpN5lbTTLlkLez40WkNPc9vw/u1J2j6DBiy0jcVX48nCkWrx2EC+bWHqC2SLp069Xw4AdnYn/qp/W5g==}
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
@@ -160,6 +160,8 @@ export async function getTxData(txid: string) {
|
||||
height: stacksHeight,
|
||||
tx: tx.hex,
|
||||
header: header,
|
||||
prevTxidVout: tx.vin.map((e: any) => { return { txid: e.txid, vout: e.vout } }),
|
||||
scriptPubKey: tx.vout.map((e: any) => e.scriptPubKey.hex),
|
||||
proof: { "tx-index": proofArg.txIndex, "hashes": proofArg.hashes.map((h) => bytesToHex(h)), "tree-depth": proofArg.treeDepth }
|
||||
}
|
||||
|
||||
@@ -176,7 +178,7 @@ if (require.main === module) {
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log(
|
||||
`Usage: pnpm tsx sscripts/extract-tx-data.ts "[txID]"`,
|
||||
`Usage: pnpm tsx scripts/extract-tx-data.ts "[txID]"`,
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
tupleCV,
|
||||
uintCV,
|
||||
stringUtf8CV,
|
||||
standardPrincipalCV,
|
||||
contractPrincipalCV,
|
||||
TupleCV
|
||||
} from '@stacks/transactions';
|
||||
import { createHash } from 'crypto';
|
||||
@@ -21,12 +23,12 @@ if (process.argv.length !== 3) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// function principalCV(input: string) {
|
||||
// const dot = input.indexOf('.');
|
||||
// return dot === -1
|
||||
// ? standardPrincipalCV(input)
|
||||
// : contractPrincipalCV(input.substring(0, dot), input.substring(dot + 1));
|
||||
// }
|
||||
function principalCV(input: string) {
|
||||
const dot = input.indexOf('.');
|
||||
return dot === -1
|
||||
? standardPrincipalCV(input)
|
||||
: contractPrincipalCV(input.substring(0, dot), input.substring(dot + 1));
|
||||
}
|
||||
|
||||
function toBuffer(input: string): Buffer {
|
||||
return Buffer.from(
|
||||
@@ -38,6 +40,8 @@ function toBuffer(input: string): Buffer {
|
||||
function txToTupleCV(tx: { [key: string]: any }) {
|
||||
const expected_struct = {
|
||||
'bitcoin-tx': (input: any) => bufferCV(toBuffer(input)),
|
||||
output: uintCV,
|
||||
offset: uintCV,
|
||||
tick: stringUtf8CV,
|
||||
amt: uintCV,
|
||||
from: (input: any) => bufferCV(toBuffer(input)),
|
||||
@@ -66,4 +70,4 @@ try {
|
||||
|
||||
const txTuple = txToTupleCV(tx);
|
||||
const hash = hashOrder(txTuple) as Buffer;
|
||||
console.log('0x' + hash.toString('hex'));
|
||||
console.log(`Tx Hash: 0x${hash.toString('hex')}`);
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
import { StacksMainnet, StacksMocknet } from '@stacks/network';
|
||||
import {
|
||||
ClarityValue,
|
||||
StacksPrivateKey,
|
||||
createStacksPrivateKey,
|
||||
serializeCV,
|
||||
signWithKey,
|
||||
stringAsciiCV,
|
||||
tupleCV,
|
||||
uintCV,
|
||||
@@ -22,7 +25,7 @@ function sha256(data: Buffer): Buffer {
|
||||
}
|
||||
|
||||
function structuredDataHash(structuredData: ClarityValue): Buffer {
|
||||
return sha256(serializeCV(structuredData));
|
||||
return sha256(Buffer.from(serializeCV(structuredData)));
|
||||
}
|
||||
|
||||
const domainHash = structuredDataHash(
|
||||
@@ -34,17 +37,17 @@ const domainHash = structuredDataHash(
|
||||
}),
|
||||
);
|
||||
|
||||
// function signStructuredData(
|
||||
// privateKey: StacksPrivateKey,
|
||||
// structuredData: ClarityValue,
|
||||
// ) {
|
||||
// const messageHash = structuredDataHash(structuredData);
|
||||
// const input = sha256(
|
||||
// Buffer.concat([structuredDataPrefix, domainHash, messageHash]),
|
||||
// );
|
||||
// const data = signWithKey(privateKey, input.toString('hex')).data;
|
||||
// return Buffer.from(data.slice(2) + data.slice(0, 2), 'hex');
|
||||
// }
|
||||
function signStructuredData(
|
||||
privateKey: StacksPrivateKey,
|
||||
structuredData: ClarityValue,
|
||||
) {
|
||||
const messageHash = structuredDataHash(structuredData);
|
||||
const input = sha256(
|
||||
Buffer.concat([structuredDataPrefix, domainHash, messageHash]),
|
||||
);
|
||||
const data = signWithKey(privateKey, input.toString('hex')).data;
|
||||
return Buffer.from(data.slice(2) + data.slice(0, 2), 'hex');
|
||||
}
|
||||
|
||||
if (process.argv.length !== 4) {
|
||||
console.log(`Usage: ts-node sign-tx-hash <private key> <tx hash>`);
|
||||
@@ -58,23 +61,22 @@ function toBuffer(input: string) {
|
||||
);
|
||||
}
|
||||
|
||||
// const private_key = process.argv[2]!;
|
||||
// const hash = process.argv[3]!;
|
||||
const private_key = process.argv[2]!;
|
||||
const hash = process.argv[3]!;
|
||||
|
||||
// const stacksPrivateKey = createStacksPrivateKey(toBuffer(private_key));
|
||||
const stacksPrivateKey = createStacksPrivateKey(toBuffer(private_key));
|
||||
|
||||
// function signTxHash(private_key: StacksPrivateKey, hash: Buffer) {
|
||||
// const message = createHash('sha256')
|
||||
// .update(Buffer.concat([structuredDataPrefix, domainHash, hash]))
|
||||
// .digest();
|
||||
// const data = signWithKey(private_key, message.toString('hex')).data;
|
||||
// return Buffer.from(data.slice(2) + data.slice(0, 2), 'hex');
|
||||
// }
|
||||
function signTxHash(private_key: StacksPrivateKey, hash: Buffer) {
|
||||
const message = createHash('sha256')
|
||||
.update(Buffer.concat([structuredDataPrefix, domainHash, hash]))
|
||||
.digest();
|
||||
const data = signWithKey(private_key, message.toString('hex')).data;
|
||||
return Buffer.from(data.slice(2) + data.slice(0, 2), 'hex');
|
||||
}
|
||||
|
||||
console.log(structuredDataPrefix.toString('hex'));
|
||||
console.log(domainHash.toString('hex'));
|
||||
// console.log(hash);
|
||||
console.log(`Structured Data Prefix: ${structuredDataPrefix.toString('hex')}`);
|
||||
console.log(`Domain Hash: ${domainHash.toString('hex')}`);
|
||||
|
||||
// const signature = signTxHash(stacksPrivateKey, toBuffer(hash));
|
||||
const signature = signTxHash(stacksPrivateKey, toBuffer(hash));
|
||||
|
||||
// console.log('0x' + signature.toString('hex'));
|
||||
console.log(`Signature: 0x${signature.toString('hex')}`);
|
||||
|
||||
72
settings/Development.toml
Normal file
72
settings/Development.toml
Normal file
@@ -0,0 +1,72 @@
|
||||
[network]
|
||||
name = "Development"
|
||||
|
||||
[accounts.deployer]
|
||||
mnemonic = "twice kind fence tip hidden tilt action fragile skin nothing glory cousin green tomorrow spring wrist shed math olympic multiply hip blue scout claw"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601
|
||||
# stx_address: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
|
||||
# btc_address: mqVnk6NPRdhntvfm4hh9vvjiRkFDUuSYsH
|
||||
|
||||
[accounts.wallet_1]
|
||||
mnemonic = "sell invite acquire kitten bamboo drastic jelly vivid peace spawn twice guilt pave pen trash pretty park cube fragile unaware remain midnight betray rebuild"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801
|
||||
# stx_address: ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5
|
||||
# btc_address: mr1iPkD9N3RJZZxXRk7xF9d36gffa6exNC
|
||||
|
||||
[accounts.wallet_2]
|
||||
mnemonic = "hold excess usual excess ring elephant install account glad dry fragile donkey gaze humble truck breeze nation gasp vacuum limb head keep delay hospital"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101
|
||||
# stx_address: ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
|
||||
# btc_address: muYdXKmX9bByAueDe6KFfHd5Ff1gdN9ErG
|
||||
|
||||
[accounts.wallet_3]
|
||||
mnemonic = "cycle puppy glare enroll cost improve round trend wrist mushroom scorpion tower claim oppose clever elephant dinosaur eight problem before frozen dune wagon high"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: d655b2523bcd65e34889725c73064feb17ceb796831c0e111ba1a552b0f31b3901
|
||||
# stx_address: ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
|
||||
# btc_address: mvZtbibDAAA3WLpY7zXXFqRa3T4XSknBX7
|
||||
|
||||
[accounts.wallet_4]
|
||||
mnemonic = "board list obtain sugar hour worth raven scout denial thunder horse logic fury scorpion fold genuine phrase wealth news aim below celery when cabin"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: f9d7206a47f14d2870c163ebab4bf3e70d18f5d14ce1031f3902fbbc894fe4c701
|
||||
# stx_address: ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND
|
||||
# btc_address: mg1C76bNTutiCDV3t9nWhZs3Dc8LzUufj8
|
||||
|
||||
[accounts.wallet_5]
|
||||
mnemonic = "hurry aunt blame peanut heavy update captain human rice crime juice adult scale device promote vast project quiz unit note reform update climb purchase"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 3eccc5dac8056590432db6a35d52b9896876a3d5cbdea53b72400bc9c2099fe801
|
||||
# stx_address: ST2REHHS5J3CERCRBEPMGH7921Q6PYKAADT7JP2VB
|
||||
# btc_address: mweN5WVqadScHdA81aATSdcVr4B6dNokqx
|
||||
|
||||
[accounts.wallet_6]
|
||||
mnemonic = "area desk dutch sign gold cricket dawn toward giggle vibrant indoor bench warfare wagon number tiny universe sand talk dilemma pottery bone trap buddy"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01
|
||||
# stx_address: ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0
|
||||
# btc_address: mzxXgV6e4BZSsz8zVHm3TmqbECt7mbuErt
|
||||
|
||||
[accounts.wallet_7]
|
||||
mnemonic = "prevent gallery kind limb income control noise together echo rival record wedding sense uncover school version force bleak nuclear include danger skirt enact arrow"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: b463f0df6c05d2f156393eee73f8016c5372caa0e9e29a901bb7171d90dc4f1401
|
||||
# stx_address: ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ
|
||||
# btc_address: n37mwmru2oaVosgfuvzBwgV2ysCQRrLko7
|
||||
|
||||
[accounts.wallet_8]
|
||||
mnemonic = "female adjust gallery certain visit token during great side clown fitness like hurt clip knife warm bench start reunion globe detail dream depend fortune"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: 6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01
|
||||
# stx_address: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP
|
||||
# btc_address: n2v875jbJ4RjBnTjgbfikDfnwsDV5iUByw
|
||||
|
||||
[accounts.wallet_9]
|
||||
mnemonic = "shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform"
|
||||
balance = 100_000_000_000_000
|
||||
# secret_key: de433bdfa14ec43aa1098d5be594c8ffb20a31485ff9de2923b2689471c401b801
|
||||
# stx_address: STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6
|
||||
# btc_address: mjSrB3wS4xab3kYqFktwBzfTdPg367ZJ2d
|
||||
@@ -1,22 +0,0 @@
|
||||
export type {
|
||||
Account,
|
||||
ReadOnlyFn,
|
||||
} from "https://deno.land/x/clarinet@v1.3.1/index.ts";
|
||||
|
||||
export {
|
||||
Clarinet,
|
||||
Chain,
|
||||
Tx,
|
||||
types,
|
||||
} from "https://deno.land/x/clarinet@v1.3.1/index.ts";
|
||||
|
||||
export {
|
||||
assertEquals,
|
||||
assertObjectMatch,
|
||||
} from "https://deno.land/std@0.125.0/testing/asserts.ts";
|
||||
|
||||
export {
|
||||
beforeEach,
|
||||
describe,
|
||||
it,
|
||||
} from "https://deno.land/x/test_suite@0.9.5/mod.ts";
|
||||
186
tests/includes.ts
Normal file
186
tests/includes.ts
Normal file
@@ -0,0 +1,186 @@
|
||||
// deno-lint-ignore-file no-explicit-any ban-types
|
||||
import {
|
||||
Account,
|
||||
Chain,
|
||||
Clarinet,
|
||||
Tx,
|
||||
types,
|
||||
} from "https://deno.land/x/clarinet@v1.3.1/index.ts";
|
||||
export { assertEquals } from 'https://deno.land/std@0.166.0/testing/asserts.ts';
|
||||
export { Clarinet, Tx, Chain, types };
|
||||
export type { Account };
|
||||
export { contractNames };
|
||||
export { uintCV, principalCV, noneCV, someCV, tupleCV };
|
||||
|
||||
const contractNames = {
|
||||
indexer: 'indexer',
|
||||
registry: 'indexer-registry'
|
||||
};
|
||||
|
||||
const uintCV = types.uint;
|
||||
const principalCV = types.principal;
|
||||
const noneCV = types.none;
|
||||
const someCV = types.some;
|
||||
const bufferCV = types.buff;
|
||||
const tupleCV = types.tuple;
|
||||
const boolCV = types.bool;
|
||||
const stringUtf8CV = types.utf8;
|
||||
const listCV = types.list;
|
||||
|
||||
export const buff = (input: string | ArrayBuffer) =>
|
||||
typeof input === 'string'
|
||||
? input.length >= 2 && input[1] === 'x'
|
||||
? input
|
||||
: `0x${input}`
|
||||
: bufferCV(input);
|
||||
|
||||
export function txToTuple(tx: { [key: string]: any }) {
|
||||
const expected_struct = {
|
||||
'bitcoin-tx': (input: any) => buff(input),
|
||||
output: uintCV,
|
||||
offset: uintCV,
|
||||
tick: stringUtf8CV,
|
||||
amt: uintCV,
|
||||
from: (input: any) => buff(input),
|
||||
to: (input: any) => buff(input),
|
||||
'from-bal': uintCV,
|
||||
'to-bal': uintCV
|
||||
};
|
||||
const txTuple: { [key: string]: any } = {};
|
||||
for (const [key, func] of Object.entries(expected_struct))
|
||||
if (key in tx) txTuple[key] = func(tx[key]);
|
||||
else throw new Error(`Tx object missing '${key}' field`);
|
||||
|
||||
return txTuple;
|
||||
}
|
||||
|
||||
export function txToTupleCV(tx: { [key: string]: any }) {
|
||||
return tupleCV(txToTuple(tx));
|
||||
}
|
||||
|
||||
export function proofToTuple(proof: { [key: string]: any }) {
|
||||
const expected_struct = {
|
||||
hashes: (input: any) => listCV(input.map((e: any) => buff(e))),
|
||||
"tree-depth": uintCV,
|
||||
"tx-index": uintCV
|
||||
}
|
||||
const proofTuple: { [key: string]: any } = {};
|
||||
for (const [key, func] of Object.entries(expected_struct))
|
||||
if (key in proof) proofTuple[key] = func(proof[key]);
|
||||
else throw new Error(`Proof object missing '${key}' field`);
|
||||
|
||||
return proofTuple;
|
||||
}
|
||||
|
||||
export function proofToTupleCV(proof: { [key: string]: any }) {
|
||||
return tupleCV(proofToTuple(proof));
|
||||
}
|
||||
|
||||
export function headerToTuple(header: { [key: string]: any }) {
|
||||
const expected_struct = {
|
||||
header: (input: any) => buff(input),
|
||||
height: uintCV
|
||||
}
|
||||
const headerTuple: { [key: string]: any } = {};
|
||||
for (const [key, func] of Object.entries(expected_struct))
|
||||
if (key in header) headerTuple[key] = func(header[key]);
|
||||
else throw new Error(`Header object missing '${key}' field`);
|
||||
|
||||
return headerTuple;
|
||||
}
|
||||
|
||||
export function headerToTupleCV(header: { [key: string]: any }) {
|
||||
return tupleCV(headerToTuple(header));
|
||||
}
|
||||
|
||||
export function signPackToTuple(signPack: { [key: string]: any }) {
|
||||
const expected_struct = {
|
||||
"tx-hash": (input: any) => buff(input),
|
||||
signature: (input: any) => buff(input),
|
||||
signer: principalCV
|
||||
}
|
||||
const signPackTuple: { [key: string]: any } = {};
|
||||
for (const [key, func] of Object.entries(expected_struct))
|
||||
if (key in signPack) signPackTuple[key] = func(signPack[key]);
|
||||
else throw new Error(`SignPack object missing '${key}' field`);
|
||||
|
||||
return signPackTuple;
|
||||
}
|
||||
|
||||
export function signPackToTupleCV(signPack: { [key: string]: any }) {
|
||||
return tupleCV(signPackToTuple(signPack));
|
||||
}
|
||||
|
||||
export function prepareChainBasicTest(
|
||||
chain: Chain,
|
||||
accounts: Map<string, Account>,
|
||||
) {
|
||||
const deployer = accounts.get('deployer')!;
|
||||
const wallet_1 = accounts.get('wallet_1')!; //validator
|
||||
const wallet_2 = accounts.get('wallet_2')!; //relayer
|
||||
const wallet_3 = accounts.get('wallet_3')!; //relayer
|
||||
|
||||
const wallet_1_pubkey =
|
||||
'03cd2cfdbd2ad9332828a7a13ef62cb999e063421c708e863a7ffed71fb61c88c9';
|
||||
const wallet_2_pubkey =
|
||||
'021843d01fa0bb9a3495fd2caf92505a81055dbe1fd545880fd40c3a1c7fd9c40a';
|
||||
const wallet_3_pubkey =
|
||||
'02c4b5eacb71a27be633ed970dcbc41c00440364bc04ba38ae4683ac24e708bf33';
|
||||
|
||||
return chain.mineBlock([
|
||||
Tx.contractCall(
|
||||
"indexer-registry",
|
||||
"approve-operator",
|
||||
['.' + contractNames.indexer, types.bool(true)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"set-paused",
|
||||
[types.bool(false)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"set-required-validators",
|
||||
[types.uint(1)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"add-validator",
|
||||
[
|
||||
buff(wallet_1_pubkey),
|
||||
types.principal(wallet_1.address)
|
||||
],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"approve-relayer",
|
||||
[
|
||||
types.principal(wallet_2.address),
|
||||
types.bool(true)
|
||||
],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall( // for live-testing
|
||||
"indexer",
|
||||
"add-validator",
|
||||
[
|
||||
buff('02883d08893252a59cf25aafffe1417bf74a7526621665a4bc0060e4aa95405891'),
|
||||
types.principal('SP1B0DHZV858RCBC8WG1YN5W9R491MJK88QPPC217')
|
||||
],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall( // for live-testing
|
||||
"indexer",
|
||||
"approve-relayer",
|
||||
[
|
||||
types.principal('SPMTYQTVWDH61Z0354KHD8EQQ36V8DX5R67P3DD0'),
|
||||
types.bool(true)
|
||||
],
|
||||
deployer.address
|
||||
)
|
||||
]);
|
||||
}
|
||||
@@ -1,35 +1,133 @@
|
||||
import { Clarinet, Tx, Chain, Account, types, assertEquals } from "./deps.ts";
|
||||
import { hexToBytes, expectHeaderObject, expectTxObject } from "./utils.ts";
|
||||
|
||||
Clarinet.test({
|
||||
name: "clarity-bitcoin can parse and verify tx",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>) {
|
||||
const deployer = accounts.get("deployer")!;
|
||||
|
||||
const b_hash = chain.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"get-bc-h-hash",
|
||||
[types.uint(801723)],
|
||||
deployer.address
|
||||
)
|
||||
console.log(b_hash);
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import {
|
||||
Account,
|
||||
assertEquals,
|
||||
buff,
|
||||
Chain,
|
||||
Clarinet,
|
||||
contractNames,
|
||||
headerToTuple,
|
||||
headerToTupleCV,
|
||||
prepareChainBasicTest,
|
||||
proofToTuple,
|
||||
proofToTupleCV,
|
||||
signPackToTupleCV,
|
||||
Tx,
|
||||
txToTuple,
|
||||
txToTupleCV,
|
||||
types,
|
||||
} from './includes.ts';
|
||||
|
||||
// https://mempool.space/api/tx/70796b5087799c71965a35d8a8add91f2fc14cab6baac6c58fd2c5fe48913611
|
||||
const deploy_data = "0x02000000000101df8ef516ae29b6f5320e6f7be966d134073fd608187de50c58821672e35896f00000000000fdffffff02220200000000000022512097c010ad464a48b77491113aded0570ce8b32090ba925b6290e5ba97268e3c7c1a0d000000000000160014b492459705c999f9c4ec329a815d3a32909cd880034022cf8cb19d3ae16f174dd965ea310bc03387e99bda8ff0cf6998f085687c0e6c03de7dbfab5b7dcfe0f48344b66cbbe23f4bb26e5ba39a7d814f2c684bddfe0f9b20117f692257b2331233b5705ce9c682be8719ff1b2b64cbca290bd6faeb54423eac061234cf098801750063036f7264010118746578742f706c61696e3b636861727365743d7574662d38004c4c7b2270223a226272632d3230222c226f70223a226465706c6f79222c227469636b223a2224423230222c226d6178223a223231303030303030222c226c696d223a223231303030303030227d6821c0117f692257b2331233b5705ce9c682be8719ff1b2b64cbca290bd6faeb54423e00000000";
|
||||
// pnpm tsx scripts/extract-tx-data.ts 70796b5087799c71965a35d8a8add91f2fc14cab6baac6c58fd2c5fe48913611
|
||||
const deploy_txid = '0x70796b5087799c71965a35d8a8add91f2fc14cab6baac6c58fd2c5fe48913611';
|
||||
const deploy_data =
|
||||
{
|
||||
burnHeight: 789219,
|
||||
height: 105098,
|
||||
tx: '02000000000101df8ef516ae29b6f5320e6f7be966d134073fd608187de50c58821672e35896f00000000000fdffffff02220200000000000022512097c010ad464a48b77491113aded0570ce8b32090ba925b6290e5ba97268e3c7c1a0d000000000000160014b492459705c999f9c4ec329a815d3a32909cd880034022cf8cb19d3ae16f174dd965ea310bc03387e99bda8ff0cf6998f085687c0e6c03de7dbfab5b7dcfe0f48344b66cbbe23f4bb26e5ba39a7d814f2c684bddfe0f9b20117f692257b2331233b5705ce9c682be8719ff1b2b64cbca290bd6faeb54423eac061234cf098801750063036f7264010118746578742f706c61696e3b636861727365743d7574662d38004c4c7b2270223a226272632d3230222c226f70223a226465706c6f79222c227469636b223a2224423230222c226d6178223a223231303030303030222c226c696d223a223231303030303030227d6821c0117f692257b2331233b5705ce9c682be8719ff1b2b64cbca290bd6faeb54423e00000000',
|
||||
header: '000099247386511af242d00e8ee3773996d90c293e0b8e3974ba0500000000000000000050ae942b1b7052581eff46d43d26d4133cc3ce9a7be1cbb81318c27b54cf27099d9f5c6401dd051722911240',
|
||||
proof: {
|
||||
'tx-index': 603,
|
||||
hashes: [
|
||||
'a1f6564581a409bf3d52c87ea8164e0899d20df9c946af2794d4b408a10a86d9',
|
||||
'5ee7f8ae5576636d2b36540164b12a8c7f171a382e92b3313c999c022ad62b59',
|
||||
'e95ccfd8da89610069cd08dca041ac587bace26880a1f6b3847ff56c78068b06',
|
||||
'1b239752cb61b6dbd6726795af70e7a2cdaee3929c51a1f655417fc22ebd3c0a',
|
||||
'0b7bb231b7e8a6bb4cf4967444efd4f28ae95370781e634dba7273016f488fcf',
|
||||
'5af25cccb1eead88515d34e068f19e9d1f5d1a7d33ce4f5d1ada6d92364ce3dc',
|
||||
'bee7d7710e557deb14cf7961c19c981afb70ffc307c1695c24362eaf37e5cd0c',
|
||||
'ebac6ae575e22cdb63847931454d8ca828c6cae6ec85b2aab35c32057133d354',
|
||||
'd6a106be86e0b533bd7459c589b0abd317fa6fe84bd83676188a2bf493a10093',
|
||||
'65a68bc14a6555d287ce799659ca0b3225df9df5dbf18992763267d5852637e4',
|
||||
'462e3648c61f1e3033d009e3447ad5cba5d85be96c7525e8cef391a6c9170e6f',
|
||||
'4fb85cf869308cd73f73258a9d10f5e07da27cf54b2d49290ab0b85476f42e57',
|
||||
'0cab2ef841bbd34607ff152fa4fdd7dc33b06cd34a8a21cd91bf0321a3c60f0a'
|
||||
],
|
||||
'tree-depth': 13
|
||||
}
|
||||
};
|
||||
|
||||
// https://mempool.space/api/tx/2e951004175cbc4a0a421efbb5a42aaa4e4708c1bc15a08ab03e41020336603b/hex
|
||||
// pnpm tsx scripts/extract-tx-data.ts 2e951004175cbc4a0a421efbb5a42aaa4e4708c1bc15a08ab03e41020336603b
|
||||
const transferrable_txid = '0x2e951004175cbc4a0a421efbb5a42aaa4e4708c1bc15a08ab03e41020336603b';
|
||||
const transferrable_data =
|
||||
"0x01000000000101885a283122b9897aa8ccfbd1b6ee8e88a81f297039506f1310ac0999fd0ec1c20000000000fdffffff01220200000000000022512053687745b1a04c2d74da5f1aa12d285df92626384fc5697de94ba6b9b9afee650340703b0cf0c88bd1e890d5b52a425cd37d4fa35e911423bf6306faeff09a98ff5c5afaf79fe02b5423771c2396abec0851af8d59896f5960b1869aa2d6323ea8927f2006449df0d86cb0c82057dfaa9dad498131215190799a442772d3407e0c0b02a7ac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800397b2270223a226272632d3230222c226f70223a227472616e73666572222c227469636b223a2269676c69222c22616d74223a2232303030227d6821c106449df0d86cb0c82057dfaa9dad498131215190799a442772d3407e0c0b02a700000000";
|
||||
{
|
||||
burnHeight: 794680,
|
||||
height: 109655,
|
||||
tx: '01000000000101885a283122b9897aa8ccfbd1b6ee8e88a81f297039506f1310ac0999fd0ec1c20000000000fdffffff01220200000000000022512053687745b1a04c2d74da5f1aa12d285df92626384fc5697de94ba6b9b9afee650340703b0cf0c88bd1e890d5b52a425cd37d4fa35e911423bf6306faeff09a98ff5c5afaf79fe02b5423771c2396abec0851af8d59896f5960b1869aa2d6323ea8927f2006449df0d86cb0c82057dfaa9dad498131215190799a442772d3407e0c0b02a7ac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800397b2270223a226272632d3230222c226f70223a227472616e73666572222c227469636b223a2269676c69222c22616d74223a2232303030227d6821c106449df0d86cb0c82057dfaa9dad498131215190799a442772d3407e0c0b02a700000000',
|
||||
header: '0040002094c612a35b16f031dc589dccef93a671e763e00efc6c02000000000000000000f42688ac3b24036b38263f73f1ba1ae5924057fe8a6390b25e8b367f2fe0f53bf3f68c646d6005179da8a102',
|
||||
proof: {
|
||||
'tx-index': 382,
|
||||
hashes: [
|
||||
'417dbc049f86e060b862073054469b9da9bc92e6a8f39d94c0344f4e1355e3b4',
|
||||
'1a92bb4b9d4d821ea26b33503a24f132d8ac49cf085543a28da684f32b3d197b',
|
||||
'6e19bc2d92439878adb32a0298191fac2fc05781ca5f3e266fcb2b588b20e3c9',
|
||||
'b5ccdf94b47093853aeb465170a51be66b92c1043ae120552ff5eb191d522c50',
|
||||
'15434283b374b5e4289e4f4aa44b1321b5db03747139d7cabcf4c611eb941f53',
|
||||
'a4def5491336a883410b653ec91162acf4bfe853e2a6287ad6d6f4337f9a60bb',
|
||||
'a969dde4d0c97d87a2b9704344127aaeb26a1678897632f31610bfd8dd5d8d77',
|
||||
'504461d569bd51ab1c8c51ee1e834fe19fd5936fb6a9aaecfb348fb2926436c3',
|
||||
'460b473528cc1e9306c8a316add3260ea2339bc43de8dfebfb69448394911f95',
|
||||
'c7aef7e665ec086443a282d1fff887f43ebd79728b6a2dbe4b18d7635f0793bf',
|
||||
'd383fbfea7f4268208cbc92e3ae879eb6b4b3cc323bafb5185426c3decb593dd',
|
||||
'5f33844bff468cb7f0d5104ce9c5c266b0b125db2e5f8b55458a8c66d9487192'
|
||||
],
|
||||
'tree-depth': 12
|
||||
}
|
||||
}
|
||||
|
||||
// https://mempool.space/api/tx/5760346ab0ebb18084432eea1c8f921f36e2517e0e3fea9741a1523cd5e47feb/hex
|
||||
// pnpm tsx scripts/extract-tx-data.ts 5760346ab0ebb18084432eea1c8f921f36e2517e0e3fea9741a1523cd5e47feb
|
||||
const transfer_txid = '0x5760346ab0ebb18084432eea1c8f921f36e2517e0e3fea9741a1523cd5e47feb';
|
||||
const transfer_data =
|
||||
"0x020000000001023b60360302413eb08aa015bcc108474eaa2aa4b5fb1e420a4abc5c170410952e0000000000ffffffffad4836f6077e2a02a2ac0198a70374759f8fece545d2c0e12b5ba9ca9efc3fc50400000017160014770dea24279344035fbb90eab3a156b43c183decffffffff022202000000000000225120c981bdfa5eaab9d6d0da158144e1c519411e76bf11e4c5deba73b358431b53b70a7300000000000017a914fe8b7a0c78c3af44ceea9e2b033d9220631ecf9e8701401442fa68d11c85791ffd3a7efa5ceedaa4bb51ee280c0b428f4ce2c6041261a1bee22084c073efff332d6264db9e84533d8aed41ddaee96cb166fdbb70a634f802483045022100eedf43522e4fb9c7c8aa1daddf31f2f48aaefb0741a14d5b1dc390420b8bca2c02207718fe6f3dfd1291bc4cafd6ef73c58237df20528737029dd15f35d18d611ef6012103f7cefdc7515124973cb02a6f17704e254e08f6025636e68f43ebee86fe3c724100000000";
|
||||
{
|
||||
burnHeight: 794819,
|
||||
height: 109769,
|
||||
tx: '020000000001023b60360302413eb08aa015bcc108474eaa2aa4b5fb1e420a4abc5c170410952e0000000000ffffffffad4836f6077e2a02a2ac0198a70374759f8fece545d2c0e12b5ba9ca9efc3fc50400000017160014770dea24279344035fbb90eab3a156b43c183decffffffff022202000000000000225120c981bdfa5eaab9d6d0da158144e1c519411e76bf11e4c5deba73b358431b53b70a7300000000000017a914fe8b7a0c78c3af44ceea9e2b033d9220631ecf9e8701401442fa68d11c85791ffd3a7efa5ceedaa4bb51ee280c0b428f4ce2c6041261a1bee22084c073efff332d6264db9e84533d8aed41ddaee96cb166fdbb70a634f802483045022100eedf43522e4fb9c7c8aa1daddf31f2f48aaefb0741a14d5b1dc390420b8bca2c02207718fe6f3dfd1291bc4cafd6ef73c58237df20528737029dd15f35d18d611ef6012103f7cefdc7515124973cb02a6f17704e254e08f6025636e68f43ebee86fe3c724100000000',
|
||||
header: '00000020aeb0b24d2d6a052c12063dce70db5cef3b32d4b2feed00000000000000000000f4f2231eacd683f14838228cc7d4221f4a86f163ba5f0e35f94b35d2f0a72062d63e8e646d600517382e2a5c',
|
||||
proof: {
|
||||
'tx-index': 1151,
|
||||
hashes: [
|
||||
'55d4e980d84c3c31f3b9538dcf56a4bf8a11ec280175f3a8b96e32e255dc7e3c',
|
||||
'52a0646be2f03c64108eee7948f8ac3fa0add274ac06e5756d8ff585e1d25481',
|
||||
'572ce337af6f2777b1266d6cfc5860a62b5821cc494b5c867e136a0464dae744',
|
||||
'578abb65f25709c21232dd2ac13e1e89fc97f1b1c06404a4d97321720500c38b',
|
||||
'015458b49f57c7d35d23e48b0a821d7def627d3716e31e29a645ac0b4d96253e',
|
||||
'e85afa448d20154aa410e95658ee31d1732930817b8659b35b0c9ecf3095ca5a',
|
||||
'f0d3a992cc972edf0db390cf97e55e7e8fb0a4e08f10c236ba5dbb5e4174bb80',
|
||||
'24ff2881c0dfb8f2fcd4d88582bdc0cce1b8997ed074b06a7da7260f7831b46c',
|
||||
'efadcaddbc4b6832a1b553d40736636b0de91a81996a1c66feddd84a59849f6f',
|
||||
'9b8e5adaa212bd9538af596692e33f5a78b5023d34787c051a9efe35b208932f',
|
||||
'c981bdb80b48bcd489d4974240607186b1de49e4b52819ace0f45f623586fdde',
|
||||
'359a0995c03c1c2b961122f770fcfe8ecd9095bb94eb98111139848badee2891'
|
||||
],
|
||||
'tree-depth': 12
|
||||
}
|
||||
};
|
||||
const transfer_event =
|
||||
{
|
||||
"amt": "2000000000000000000000",
|
||||
"bitcoin-tx": "0x5760346ab0ebb18084432eea1c8f921f36e2517e0e3fea9741a1523cd5e47feb",
|
||||
"output": "0",
|
||||
"offset": "0",
|
||||
"tick": "igli",
|
||||
"from": "0x512053687745b1a04c2d74da5f1aa12d285df92626384fc5697de94ba6b9b9afee65",
|
||||
"to": "0x5120c981bdfa5eaab9d6d0da158144e1c519411e76bf11e4c5deba73b358431b53b7",
|
||||
"from-bal": "2000000000000000000000",
|
||||
"to-bal": "2000000000000000000000"
|
||||
};
|
||||
|
||||
Clarinet.test({
|
||||
name: "clarity-bitcoin: can parse and verify tx",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>) {
|
||||
const deployer = accounts.get("deployer")!;
|
||||
|
||||
const transferrable_parsed = chain
|
||||
.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"parse-wtx",
|
||||
[transferrable_data],
|
||||
[buff(transferrable_data.tx)],
|
||||
deployer.address
|
||||
)
|
||||
.result.expectOk()
|
||||
@@ -38,44 +136,33 @@ Clarinet.test({
|
||||
.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"parse-wtx",
|
||||
[transfer_data],
|
||||
[buff(transfer_data.tx)],
|
||||
deployer.address
|
||||
)
|
||||
.result.expectOk()
|
||||
.expectTuple();
|
||||
|
||||
// const deploy_burn_height = 789219;
|
||||
// const deploy_block_header = "0x000099247386511af242d00e8ee3773996d90c293e0b8e3974ba0500000000000000000050ae942b1b7052581eff46d43d26d4133cc3ce9a7be1cbb81318c27b54cf27099d9f5c6401dd051722911240";
|
||||
|
||||
const transferrable_burn_height = 794680;
|
||||
const transferrable_block_header =
|
||||
"0x0040002094c612a35b16f031dc589dccef93a671e763e00efc6c02000000000000000000f42688ac3b24036b38263f73f1ba1ae5924057fe8a6390b25e8b367f2fe0f53bf3f68c646d6005179da8a102";
|
||||
|
||||
// const transfer_burn_height = 794819;
|
||||
// const transfer_block_header = "0x00000020aeb0b24d2d6a052c12063dce70db5cef3b32d4b2feed00000000000000000000f4f2231eacd683f14838228cc7d4221f4a86f163ba5f0e35f94b35d2f0a72062d63e8e646d600517382e2a5c";
|
||||
|
||||
|
||||
const inscribe_header_hash = chain.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"get-txid",
|
||||
[transferrable_block_header],
|
||||
[buff(transferrable_data.header)],
|
||||
deployer.address
|
||||
).result;
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall(
|
||||
"clarity-bitcoin",
|
||||
"mock-add-burnchain-block-header-hash",
|
||||
[types.uint(transferrable_burn_height), inscribe_header_hash],
|
||||
[types.uint(transferrable_data.burnHeight), inscribe_header_hash],
|
||||
deployer.address
|
||||
),
|
||||
]);
|
||||
block.receipts.map(e => { e.result.expectOk() });
|
||||
block.receipts.map((e: any) => { e.result.expectOk() });
|
||||
|
||||
console.log(
|
||||
`can get classic txid of segwit tx: ${chain.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"get-segwit-txid",
|
||||
[transferrable_data],
|
||||
[buff(transferrable_data.tx)],
|
||||
deployer.address
|
||||
).result}`
|
||||
);
|
||||
@@ -83,7 +170,7 @@ Clarinet.test({
|
||||
`can get wtxid of segwit tx: ${chain.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"get-txid",
|
||||
[transferrable_data],
|
||||
[buff(transferrable_data.tx)],
|
||||
deployer.address
|
||||
).result}`
|
||||
);
|
||||
@@ -92,7 +179,7 @@ Clarinet.test({
|
||||
`can verify block header: ${chain.callReadOnlyFn(
|
||||
"clarity-bitcoin",
|
||||
"verify-block-header",
|
||||
[transferrable_block_header, types.uint(transferrable_burn_height)],
|
||||
[buff(transferrable_data.header), types.uint(transferrable_data.burnHeight)],
|
||||
deployer.address
|
||||
).result}`
|
||||
);
|
||||
@@ -102,29 +189,9 @@ Clarinet.test({
|
||||
"clarity-bitcoin",
|
||||
"was-segwit-tx-mined?",
|
||||
[
|
||||
types.tuple({
|
||||
header: transferrable_block_header,
|
||||
height: types.uint(transferrable_burn_height),
|
||||
}),
|
||||
transferrable_data,
|
||||
types.tuple({
|
||||
"tx-index": types.uint(382),
|
||||
hashes: types.list([
|
||||
"0x417dbc049f86e060b862073054469b9da9bc92e6a8f39d94c0344f4e1355e3b4",
|
||||
"0x1a92bb4b9d4d821ea26b33503a24f132d8ac49cf085543a28da684f32b3d197b",
|
||||
"0x6e19bc2d92439878adb32a0298191fac2fc05781ca5f3e266fcb2b588b20e3c9",
|
||||
"0xb5ccdf94b47093853aeb465170a51be66b92c1043ae120552ff5eb191d522c50",
|
||||
"0x15434283b374b5e4289e4f4aa44b1321b5db03747139d7cabcf4c611eb941f53",
|
||||
"0xa4def5491336a883410b653ec91162acf4bfe853e2a6287ad6d6f4337f9a60bb",
|
||||
"0xa969dde4d0c97d87a2b9704344127aaeb26a1678897632f31610bfd8dd5d8d77",
|
||||
"0x504461d569bd51ab1c8c51ee1e834fe19fd5936fb6a9aaecfb348fb2926436c3",
|
||||
"0x460b473528cc1e9306c8a316add3260ea2339bc43de8dfebfb69448394911f95",
|
||||
"0xc7aef7e665ec086443a282d1fff887f43ebd79728b6a2dbe4b18d7635f0793bf",
|
||||
"0xd383fbfea7f4268208cbc92e3ae879eb6b4b3cc323bafb5185426c3decb593dd",
|
||||
"0x5f33844bff468cb7f0d5104ce9c5c266b0b125db2e5f8b55458a8c66d9487192",
|
||||
]),
|
||||
"tree-depth": types.uint(12),
|
||||
}),
|
||||
headerToTupleCV({ header: transferrable_data.header, height: transferrable_data.burnHeight }),
|
||||
buff(transferrable_data.tx),
|
||||
proofToTupleCV(transferrable_data.proof),
|
||||
],
|
||||
deployer.address
|
||||
).result}`
|
||||
@@ -133,112 +200,62 @@ Clarinet.test({
|
||||
});
|
||||
|
||||
Clarinet.test({
|
||||
name: "indexer can hash, validate and index",
|
||||
name: "indexer: can hash, validate and index",
|
||||
async fn(chain: Chain, accounts: Map<string, Account>) {
|
||||
const deployer = accounts.get("deployer")!;
|
||||
const relayer = accounts.get("wallet_1")!;
|
||||
const validator = accounts.get("wallet_1")!;
|
||||
const relayer = accounts.get("wallet_2")!;
|
||||
|
||||
const tx = {
|
||||
amt: types.uint(5000000000000000000n),
|
||||
"bitcoin-tx": '0x0724f2a8b3c7baf69ed90e0c23c909c350cad04c139c1fde56181f72cc35091c',
|
||||
output: types.uint(0),
|
||||
offset: types.uint(0),
|
||||
tick: types.utf8('yari'),
|
||||
from: '0x5120279652ef2b9cca3cad2f1aee8ccf3bfd65f072ade8af837d6c1bdcc4ff197636',
|
||||
to: '0x5120da2cee6145154c03c7507e4bbe574ffbea1b7efd154941c47a0f1cb406cd2409',
|
||||
"from-bal": types.uint(15000000000000000000n),
|
||||
"to-bal": types.uint(24000000000000000000n)
|
||||
const results = prepareChainBasicTest(chain, accounts);
|
||||
results.receipts.forEach((e: any) => {
|
||||
e.result.expectOk();
|
||||
});
|
||||
|
||||
// please note test does not check if tx is mined.
|
||||
const tx = transfer_event;
|
||||
const header = {
|
||||
"header": transfer_data.header,
|
||||
"height": transfer_data.height
|
||||
};
|
||||
const txHash = '0x361780849133cdc391e344e43abd694b002aa15860bd1ed814225c74d9bf600b';
|
||||
const proof = transfer_data.proof;
|
||||
|
||||
// ts-node scripts/generate-tx-hash.ts 'tx'
|
||||
const txHash = "0x787e5295574228227cecc76ad31d42600ceb494c476ab57f73c8c15f0acf0205";
|
||||
|
||||
// ts-node scripts/sign-tx-hash '7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801' 'txHash'
|
||||
const signaturePack = {
|
||||
signature: '0x0455e1bd4bc02a79f4c16613c0be94cdd0929e148f6e867742426126c7648df57cf840eb586fb436bd9a01bd2d7ba8528c7dd737aff4886a0e852ea304fbfd8700',
|
||||
signer: types.principal('SP1B0DHZV858RCBC8WG1YN5W9R491MJK88QPPC217'),
|
||||
signature: "0x54bbe36fcee982fc7535ff1aaaaae8da69b5ecbd181423a6c14efaf5caae6e6442e2002082c957f07569a766f9db1ff2e1b9d77f9f37e8ab3bf771efba39ddf200",
|
||||
signer: validator.address,
|
||||
"tx-hash": txHash
|
||||
};
|
||||
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall(
|
||||
"indexer-registry",
|
||||
"approve-operator",
|
||||
[types.principal('.indexer'), types.bool(true)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"set-paused",
|
||||
[types.bool(true)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"set-required-validators",
|
||||
[types.uint(1)],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"add-validator",
|
||||
[
|
||||
'0x02883d08893252a59cf25aafffe1417bf74a7526621665a4bc0060e4aa95405891',
|
||||
types.principal('SP1B0DHZV858RCBC8WG1YN5W9R491MJK88QPPC217')
|
||||
],
|
||||
deployer.address
|
||||
),
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"approve-relayer",
|
||||
[
|
||||
types.principal(relayer.address)
|
||||
],
|
||||
deployer.address
|
||||
)
|
||||
]);
|
||||
block.receipts.map(e => { e.result.expectOk() });
|
||||
|
||||
const hashed = chain.callReadOnlyFn("indexer", "hash-tx", [types.tuple(tx)], deployer.address).result;
|
||||
const hashed = chain.callReadOnlyFn("indexer", "hash-tx", [txToTupleCV(tx)], deployer.address).result;
|
||||
assertEquals(hashed, txHash);
|
||||
console.log(`can hash tx correctly: ${hashed == txHash}`);
|
||||
|
||||
console.log(
|
||||
`can validate tx: ${chain.callReadOnlyFn("indexer", "validate-tx", [txHash, types.tuple(signaturePack)], deployer.address).result}`
|
||||
`can validate tx: ${chain.callReadOnlyFn("indexer", "validate-tx", [txHash, signPackToTupleCV(signaturePack)], deployer.address).result}`
|
||||
);
|
||||
|
||||
block = chain.mineBlock([
|
||||
let block = chain.mineBlock([
|
||||
Tx.contractCall(
|
||||
"indexer",
|
||||
"index-tx-many",
|
||||
[
|
||||
types.list([
|
||||
types.tuple({
|
||||
block: types.tuple({
|
||||
header: '0x0000d02c2279577963d4051f49d2c6b63701811cd2064eb3a3e1010000000000000000001d64bce2fd969dd1932d6b1fa97a261cce58758cb4c91dce9960ef3d7f5a6e3c2240c0649438051716d99b0e',
|
||||
height: types.uint(800258)
|
||||
}),
|
||||
proof: types.tuple({
|
||||
hashes: types.list([
|
||||
'0x19d017b157aab7df829f231ff050dddec65e5f331a7d12a53acab229381b82f3',
|
||||
'0xd59a1af2820a8f0b26ae9acc2add83909afcb777bb9f547b94afb52ab8ea3aa4',
|
||||
'0x7bed64d27dc371e40760c096405920efd6c064d8aad2c2b7780b0080709ecd1f',
|
||||
'0x8622ba1d8e890d12a48179539fabf5bc7eb7bc4bc3efd4248e1a906ff146fc29',
|
||||
'0xd4d596cdf3e2842ff4d62a96ab9bc4e5be7cb89855a1ac7e0872468a0e9fd206',
|
||||
'0x103c3c4fea3ec14f44899f7296bfc23ff8b1ddf1ccd40b8073e2f3eb693bbdd0',
|
||||
'0x66997c930850113d6abab3c7d455125dec7e751521b3e11d6d5cbf829ac2aac8',
|
||||
'0xe3c36d6c2d2854593f3e1bd32ca022a48b4f265fc34b262c6da62802ff06717b',
|
||||
'0x5cc55c2ed31a6f111b27c04cc1b352a1235cccd05031045be8d1df209dcc1a20',
|
||||
'0x5f965388b8cf20280216360e9902cdfd5ca05109c3231cb32f7ff1c1f41f3816',
|
||||
'0xbeb12810cbdd3bc16505a506da562b64bde7fb6ffafef07444cd9ee4a09f6e75',
|
||||
'0x503bba3faf83a4b896637f075add0ea72056b0ca51f1df016cd445df85d9302b'
|
||||
]),
|
||||
"tree-depth": types.uint(12),
|
||||
"tx-index": types.uint(1261)
|
||||
}),
|
||||
"signature-packs": types.list([types.tuple({ ...signaturePack, tx: tx })])
|
||||
tx: txToTupleCV(tx),
|
||||
block: headerToTupleCV(header),
|
||||
proof: proofToTupleCV(proof),
|
||||
"signature-packs": types.list([signPackToTupleCV(signaturePack)])
|
||||
})
|
||||
])
|
||||
],
|
||||
relayer.address
|
||||
),
|
||||
]);
|
||||
block.receipts.map(e => { e.result.expectOk() });
|
||||
block.receipts.map((e: any) => {
|
||||
e.result.expectOk()
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user