From 5109776d6096ce7dbad583049d70b540f4a5f184 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 14:25:09 +0800 Subject: [PATCH 01/41] update e2e tests --- contrib/localnet/bitcoin-sidecar/Dockerfile | 14 ++ .../localnet/bitcoin-sidecar/js/package.json | 23 ++ .../localnet/bitcoin-sidecar/js/src/client.ts | 202 ++++++++++++++++++ .../localnet/bitcoin-sidecar/js/src/index.ts | 78 +++++++ .../localnet/bitcoin-sidecar/js/src/reveal.ts | 13 ++ .../localnet/bitcoin-sidecar/js/src/script.ts | 52 +++++ .../localnet/bitcoin-sidecar/js/src/util.ts | 1 + .../localnet/bitcoin-sidecar/js/tsconfig.json | 11 + contrib/localnet/docker-compose.yml | 13 ++ .../test_extract_bitcoin_inscription_memo.go | 44 ++++ e2e/runner/bitcoin.go | 55 ++++- e2e/runner/inscription.go | 118 ++++++++++ zetaclient/chains/bitcoin/observer/inbound.go | 4 +- 13 files changed, 625 insertions(+), 3 deletions(-) create mode 100644 contrib/localnet/bitcoin-sidecar/Dockerfile create mode 100644 contrib/localnet/bitcoin-sidecar/js/package.json create mode 100644 contrib/localnet/bitcoin-sidecar/js/src/client.ts create mode 100644 contrib/localnet/bitcoin-sidecar/js/src/index.ts create mode 100644 contrib/localnet/bitcoin-sidecar/js/src/reveal.ts create mode 100644 contrib/localnet/bitcoin-sidecar/js/src/script.ts create mode 100644 contrib/localnet/bitcoin-sidecar/js/src/util.ts create mode 100644 contrib/localnet/bitcoin-sidecar/js/tsconfig.json create mode 100644 e2e/e2etests/test_extract_bitcoin_inscription_memo.go create mode 100644 e2e/runner/inscription.go diff --git a/contrib/localnet/bitcoin-sidecar/Dockerfile b/contrib/localnet/bitcoin-sidecar/Dockerfile new file mode 100644 index 0000000000..aef54cf56d --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/Dockerfile @@ -0,0 +1,14 @@ +FROM node:18.20.4 as builder + +WORKDIR /home/zeta/node + +COPY bitcoin-sidecar/js/* . + +RUN npm install && npm install typescript -g && tsc + +FROM node:alpine + +COPY --from=builder /home/zeta/node/dist ./dist +COPY --from=builder /home/zeta/node/node_modules ./node_modules + +CMD ["node", "dist/index.js"] \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/package.json b/contrib/localnet/bitcoin-sidecar/js/package.json new file mode 100644 index 0000000000..dc6da4ffce --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/package.json @@ -0,0 +1,23 @@ +{ + "name": "zeta-btc-client", + "version": "0.0.1", + "description": "The Zetachain BTC client", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "bip32": "^4.0.0", + "bitcoinjs-lib": "^6.1.6", + "ecpair": "^2.1.0", + "express": "^4.19.2", + "randombytes": "^2.1.0", + "tiny-secp256k1": "^2.2.3" + }, + "devDependencies": { + "@types/node": "^20.14.11", + "typescript": "^5.5.3" + } +} diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts new file mode 100644 index 0000000000..514ddfe043 --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -0,0 +1,202 @@ +import { initEccLib, payments, Psbt } from "bitcoinjs-lib"; +import { bitcoin, Network, regtest } from "bitcoinjs-lib/src/networks"; +import BIP32Factory, { BIP32Interface } from 'bip32'; +import * as ecc from 'tiny-secp256k1'; +import randomBytes from "randombytes"; +import { ScriptBuilder } from "./script"; +import { Taptree } from "bitcoinjs-lib/src/types"; +import { toXOnly } from "./util"; + +const LEAF_VERSION_TAPSCRIPT = 0xc0; + +initEccLib(ecc); +const bip32 = BIP32Factory(ecc); +const rng = randomBytes; + + +export const DEFAULT_CONFIG = { + tss: { + mainnet: "bc1p24r8dky87hvauvpc3h798juvh6e3h0fw4sjfs2m4zuq99rd8p2jqt82578", + regtest: "bcrt1q7jaj5wvxvadwfz8ws6x8jdhgvrtrfn7n8sh4ks", + } +}; + +/// The evm address type, a 20 bytes hex string +export type Address = String; +export type BtcAddress = String; + +/// The BTC transactioin hash returned +export type BtcTxnHash = String; +export interface BtcInput { + txn: BtcTxnHash, + idx: number, +} + +/** + * The example client for interracting with Zetachain in BTC. There are currently two ways + * of calling a smart contract on Zetachain from BTC: + * + * - Using OP_RETURN + * - Using Witness + * + * The method used is now based on the data size. Within 80 bytes, `OP_RETURN` is used, else + * the data is written to Witness. + * + * This class handles only the case where data is more than 80 bytes. + */ +export class ZetaBtcClient { + /** The BTC network interracting with */ + readonly network: Network; + + private reveal: RevealTxnBuilder | null; + + private constructor(network: Network) { + this.network = network; + } + + public static regtest(): ZetaBtcClient { + return new ZetaBtcClient(regtest); + } + + public static mainnet(): ZetaBtcClient { + return new ZetaBtcClient(bitcoin); + } + + /** + * Call a target address and passing the data call. + * + * @param address The target zetachain evm address + * @param calldata The calldata that will be invoked on Zetachain + */ + public call( + address: Address, + calldata: Buffer, + ): Address { + if (calldata.length <= 80) { + throw Error("Use op return instead"); + } + + if (address.startsWith("0x")) { + address = address.substring(2); + } + + return this.callWithWitness(Buffer.concat([Buffer.from(address, "hex"), calldata])); + } + + private callWithWitness( + data: Buffer, + ): Address { + const internalKey = bip32.fromSeed(rng(64), this.network); + + const leafScript = this.genLeafScript(internalKey.publicKey, data); + + const scriptTree: Taptree = { output: leafScript }; + + const { address: commitAddress } = payments.p2tr({ + internalPubkey: toXOnly(internalKey.publicKey), + scriptTree, + network: this.network, + }); + + this.reveal = new RevealTxnBuilder(internalKey, leafScript, this.network); + + return commitAddress; + } + + public buildRevealTxn(commitTxn: BtcInput, commitAmount: number, feeRate: number): Buffer { + if (this.reveal === null) { + throw new Error("commit txn not built yet"); + } + + this.reveal.with_commit_tx(commitTxn, commitAmount, feeRate); + return this.reveal.dump(); + } + + private genLeafScript(publicKey: Buffer, data: Buffer,): Buffer { + const builder = ScriptBuilder.new(publicKey); + builder.pushData(data); + return builder.build(); + } +} + +class RevealTxnBuilder { + private psbt: Psbt; + private key: BIP32Interface; + private leafScript: Buffer; + private network: Network + + constructor(key: BIP32Interface, leafScript: Buffer, network: Network) { + this.psbt = new Psbt({ network });; + this.key = key; + this.leafScript = leafScript; + this.network = network; + } + + public with_commit_tx(commitTxn: BtcInput, commitAmount: number, feeRate: number): RevealTxnBuilder { + const scriptTree: Taptree = { output: this.leafScript }; + + const { output, witness } = payments.p2tr({ + internalPubkey: toXOnly(this.key.publicKey), + scriptTree, + redeem: { + output: this.leafScript, + redeemVersion: LEAF_VERSION_TAPSCRIPT, + }, + network: this.network, + }); + + this.psbt.addInput({ + hash: commitTxn.txn.toString(), + index: commitTxn.idx, + witnessUtxo: { value: commitAmount, script: output! }, + tapLeafScript: [ + { + leafVersion: LEAF_VERSION_TAPSCRIPT, + script: this.leafScript, + controlBlock: witness![witness!.length - 1], + }, + ], + }); + + this.psbt.addOutput({ + value: commitAmount - this.estimateFee(commitAmount, feeRate), + address: this.tssAddress(), + }); + + this.psbt.signAllInputs(this.key); + this.psbt.finalizeAllInputs(); + + return this; + } + + public dump(): Buffer { + return this.psbt.extractTransaction(true).toBuffer(); + } + + private estimateFee(amount: number, feeRate: number): number { + const cloned = this.psbt.clone(); + + cloned.addOutput({ + value: amount, + address: this.tssAddress(), + }); + + // should have a way to avoid signing but just providing mocked signautre + cloned.signAllInputs(this.key); + cloned.finalizeAllInputs(); + + const size = cloned.extractTransaction().virtualSize(); + return size * feeRate; + } + + private tssAddress(): string { + switch (this.network) { + case regtest: + return DEFAULT_CONFIG.tss.regtest; + case bitcoin: + return DEFAULT_CONFIG.tss.mainnet; + default: + throw Error("not supported"); + } + } +} \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/src/index.ts b/contrib/localnet/bitcoin-sidecar/js/src/index.ts new file mode 100644 index 0000000000..b2686fa06c --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/src/index.ts @@ -0,0 +1,78 @@ +import * as readline from 'readline'; +import { ZetaBtcClient, BtcInput } from "./client"; +import { randomBytes } from 'crypto'; + +import express, { Request, Response } from 'express'; + +const app = express(); +const PORT = process.env.PORT || 3000; +let zetaClient = ZetaBtcClient.regtest(); + +app.use(express.json()); + +// Middleware to parse URL-encoded bodies +app.use(express.urlencoded({ extended: true })); + +// Route to handle JSON POST requests +app.post('/commit', (req: Request, res: Response) => { + const memo: string = req.body.memo; + const address = zetaClient.call("", Buffer.from(memo, "hex")); + res.json({ address }); +}); + +// Route to handle URL-encoded POST requests +app.post('/reveal', (req: Request, res: Response) => { + const { txn, idx, amount, feeRate } = req.body; + console.log(txn, idx, amount, feeRate); + + const rawHex = zetaClient.buildRevealTxn({ txn, idx }, Number(amount), feeRate).toString("hex"); + zetaClient = ZetaBtcClient.regtest(); + res.json({ rawHex }); +}); + +// Start the server +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); + +/** + * curl --request POST --header "Content-Type: application/json" --data '{"memo":"72f080c854647755d0d9e6f6821f6931f855b9acffd53d87433395672756d58822fd143360762109ab898626556b1c3b8d3096d2361f1297df4a41c1b429471a9aa2fc9be5f27c13b3863d6ac269e4b587d8389f8fd9649859935b0d48dea88cdb40f20c"}' http://localhost:3000/commit + * curl --request POST --header "Content-Type: application/json" --data '{"txn": "7a57f987a3cb605896a5909d9ef2bf7afbf0c78f21e4118b85d00d9e4cce0c2c", "idx": 0, "amount": 1000, "feeRate": 10}' http://localhost:3000/reveal + */ +// async function main() { +// const client = ZetaBtcClient.regtest(); + +// const data = randomBytes(100); +// console.log("random", data.toString("hex")); + +// const d = client.call("", data); +// console.log("Commit address:", d); + +// // use wallet to transfer amount to the target address + +// // obtain the txn id, index, and amount +// const [commitInput, commitAmt] = await obtainTxn(); +// const txn = client.buildRevealTxn(commitInput, commitAmt, 10); +// // txn ready to be broadcasted +// console.log(txn.toString("hex")); + +// } + +// async function obtainTxn(): Promise<[BtcInput, number]> { +// const rl = readline.createInterface({ +// input: process.stdin, +// output: process.stdout +// }); + +// return new Promise((resolve) => { +// rl.question('\nInput txn hash, txn index and amount sent: ', (answer) => { +// rl.close(); + +// const parts = answer.split(" "); +// resolve([{ txn: parts[0], idx: Number(parts[1])}, Number(parts[2])]); +// }); +// }); +// } + +// main() +// .then(() => console.log("done")); \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts b/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts new file mode 100644 index 0000000000..7a4bc45394 --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts @@ -0,0 +1,13 @@ +import { ZetaBtcClient } from "./client"; + +function main() { + const client = ZetaBtcClient.regtest(); + + const data = Buffer.alloc(600); + + const d = client.call("", data); + + console.log(d); +} + +main(); \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/src/script.ts b/contrib/localnet/bitcoin-sidecar/js/src/script.ts new file mode 100644 index 0000000000..6c47ed520b --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/src/script.ts @@ -0,0 +1,52 @@ +import { opcodes, script, Stack } from "bitcoinjs-lib"; +import { toXOnly } from "./util"; + +const MAX_SCRIPT_ELEMENT_SIZE = 520; + +/** The tapscript builder for zetaclient spending script */ +export class ScriptBuilder { + private script: Stack; + + private constructor(initialScript: Stack) { + this.script = initialScript; + } + + public static new(publicKey: Buffer): ScriptBuilder { + const stack = [ + toXOnly(publicKey), + opcodes.OP_CHECKSIG, + ]; + return new ScriptBuilder(stack); + } + + public pushData(data: Buffer) { + if (data.length <= 80) { + throw new Error("data length should be more than 80 bytes"); + } + + this.script.push( + opcodes.OP_FALSE, + opcodes.OP_IF + ); + + const chunks = chunkBuffer(data, MAX_SCRIPT_ELEMENT_SIZE); + for (const chunk of chunks) { + this.script.push(chunk); + } + + this.script.push(opcodes.OP_ENDIF); + } + + public build(): Buffer { + return script.compile(this.script); + } +} + +function chunkBuffer(buffer: Buffer, chunkSize: number): Buffer[] { + const chunks = []; + for (let i = 0; i < buffer.length; i += chunkSize) { + const chunk = buffer.slice(i, i + chunkSize); + chunks.push(chunk); + } + return chunks; + } \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/src/util.ts b/contrib/localnet/bitcoin-sidecar/js/src/util.ts new file mode 100644 index 0000000000..87c4d36d0f --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/src/util.ts @@ -0,0 +1 @@ +export const toXOnly = pubKey => (pubKey.length === 32 ? pubKey : pubKey.slice(1, 33)); \ No newline at end of file diff --git a/contrib/localnet/bitcoin-sidecar/js/tsconfig.json b/contrib/localnet/bitcoin-sidecar/js/tsconfig.json new file mode 100644 index 0000000000..d58a717dcc --- /dev/null +++ b/contrib/localnet/bitcoin-sidecar/js/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "target": "es6", + "moduleResolution": "node", + "sourceMap": true, + "outDir": "dist" + }, + "lib": ["es2015"] +} diff --git a/contrib/localnet/docker-compose.yml b/contrib/localnet/docker-compose.yml index 606b4db4be..84ac504675 100644 --- a/contrib/localnet/docker-compose.yml +++ b/contrib/localnet/docker-compose.yml @@ -227,6 +227,19 @@ services: -rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99 -txindex=1 + bitcoin-node-sidecar: + build: + dockerfile: ./bitcoin-sidecar/Dockerfile + container_name: bitcoin-node-sidecar + hostname: bitcoin-node-sidecar + networks: + mynetwork: + ipv4_address: 172.20.0.111 + environment: + - PORT=8000 + ports: + - "8000:8000" + solana: image: solana-local:latest container_name: solana diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go new file mode 100644 index 0000000000..500381d7d7 --- /dev/null +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -0,0 +1,44 @@ +package e2etests + +import ( + "github.com/stretchr/testify/require" + zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin" + btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer" + + "github.com/zeta-chain/zetacore/e2e/runner" +) + +func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { + require.Len(r, args, 2) + + r.SetBtcAddress(r.Name, false) + + r.InscribeToTSSFromDeployerWithMemo() + _, err := r.GenerateToAddressIfLocalBitcoin(6, r.BTCDeployerAddress) + require.NoError(r, err) + gtx, err := r.BtcRPCClient.GetTransaction(txid) + require.NoError(r, err) + r.Logger.Info("rawtx confirmation: %d", gtx.BlockIndex) + rawtx, err := r.BtcRPCClient.GetRawTransactionVerbose(txid) + require.NoError(r, err) + + depositorFee := zetabitcoin.DefaultDepositorFee + events, err := btcobserver.FilterAndParseIncomingTx( + r.BtcRPCClient, + []btcjson.TxRawResult{*rawtx}, + 0, + r.BTCTSSAddress.EncodeAddress(), + log.Logger, + r.BitcoinParams, + depositorFee, + ) + require.NoError(r, err) + r.Logger.Info("bitcoin inbound events:") + for _, event := range events { + r.Logger.Info(" TxHash: %s", event.TxHash) + r.Logger.Info(" From: %s", event.FromAddress) + r.Logger.Info(" To: %s", event.ToAddress) + r.Logger.Info(" Amount: %f", event.Value) + r.Logger.Info(" Memo: %x", event.MemoBytes) + } +} diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 3a4dad583e..3380845a7b 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -2,7 +2,9 @@ package runner import ( "bytes" + "encoding/hex" "fmt" + "net/http" "sort" "time" @@ -176,9 +178,17 @@ func (r *E2ERunner) SendToTSSFromDeployerWithMemo( amount float64, inputUTXOs []btcjson.ListUnspentResult, memo []byte, +) (*chainhash.Hash, error) { + return r.sendToTSSFromDeployerWithMemo(amount, r.BTCTSSAddress, inputUTXOs, memo) +} + +func (r *E2ERunner) sendToTSSFromDeployerWithMemo( + amount float64, + to btcutil.Address, + inputUTXOs []btcjson.ListUnspentResult, + memo []byte, ) (*chainhash.Hash, error) { btcRPC := r.BtcRPCClient - to := r.BTCTSSAddress btcDeployerAddress := r.BTCDeployerAddress require.NotNil(r, r.BTCDeployerAddress, "btcDeployerAddress is nil") @@ -286,6 +296,49 @@ func (r *E2ERunner) SendToTSSFromDeployerWithMemo( return txid, nil } +func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( + amount float64, + inputUTXOs []btcjson.ListUnspentResult, + memo []byte, +) (*chainhash.Hash, error) { + builder := InscriptionBuilder{sidecarUrl: "http://localhost:8000", client: http.Client{}} + + address, err := builder.GenerateCommitAddress(memo) + if err != nil { + return nil, err + } + + txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, address, inputUTXOs, memo) + if err != nil { + return nil, err + } + + // sendToTSSFromDeployerWithMemo makes sure index is 0 + outpointIdx := 0 + hexTx, err := builder.GenerateRevealTxn(txnHash.String(), outpointIdx, amount) + if err != nil { + return nil, err + } + + // Decode the hex string into raw bytes + rawTxBytes, err := hex.DecodeString(hexTx) + if err != nil { + return nil, err + } + + // Deserialize the raw bytes into a wire.MsgTx structure + msgTx := wire.NewMsgTx(wire.TxVersion) + if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { + return nil, err + } + + txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) + require.NoError(r, err) + r.Logger.Info("txid: %+v", txid) + + return txid, nil +} + // GetBitcoinChainID gets the bitcoin chain ID from the network params func (r *E2ERunner) GetBitcoinChainID() int64 { chainID, err := chains.BitcoinChainIDFromNetworkName(r.BitcoinParams.Name) diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go new file mode 100644 index 0000000000..4feb34c587 --- /dev/null +++ b/e2e/runner/inscription.go @@ -0,0 +1,118 @@ +package runner + +import ( + "bytes" + "encoding/hex" + "encoding/json" + "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcutil" + "github.com/pkg/errors" + "io" + "net/http" +) + +type commitResponse struct { + Address string `json:"address"` +} + +type revealResponse struct { + RawHex string `json:"rawHex"` +} + +type revealRequest struct { + Txn string `json:"txn"` + Idx int `json:"idx"` + Amount int `json:"amount"` + FeeRate int `json:"feeRate"` +} + +// InscriptionBuilder is a util struct that help create inscription commit and reveal transactions +type InscriptionBuilder struct { + sidecarUrl string + client http.Client +} + +func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (btcutil.Address, error) { + // Create the payload + postData := map[string]string{ + "memo": hex.EncodeToString(memo), + } + + // Convert the payload to JSON + jsonData, err := json.Marshal(postData) + if err != nil { + return nil, err + } + + postUrl := r.sidecarUrl + "/commit" + req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) + if err != nil { + return nil, errors.Wrap(err, "cannot create commit request") + } + req.Header.Set("Content-Type", "application/json") + + // Send the request + resp, err := r.client.Do(req) + if err != nil { + return nil, errors.Wrap(err, "cannot send to sidecar") + } + defer resp.Body.Close() + + // Read the response body + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "cannot read commit response body") + } + + // Parse the JSON response + var response commitResponse + if err := json.Unmarshal(body, &response); err != nil { + return nil, errors.Wrap(err, "cannot parse commit response body") + } + + return btcutil.DecodeAddress(response.Address, &chaincfg.RegressionNetParams) +} + +func (r *InscriptionBuilder) GenerateRevealTxn(txnHash string, idx int, amount float64) (string, error) { + postData := revealRequest{ + Txn: txnHash, + Idx: idx, + Amount: int(amount * 100000000), + FeeRate: 10, + } + + // Convert the payload to JSON + jsonData, err := json.Marshal(postData) + if err != nil { + return "", err + } + + postUrl := r.sidecarUrl + "/reveal" + req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) + if err != nil { + return "", errors.Wrap(err, "cannot create reveal request") + } + req.Header.Set("Content-Type", "application/json") + + // Send the request + resp, err := r.client.Do(req) + if err != nil { + return "", errors.Wrap(err, "cannot send reveal to sidecar") + } + defer resp.Body.Close() + + // Read the response body + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", errors.Wrap(err, "cannot read reveal response body") + } + + // Parse the JSON response + var response revealResponse + if err := json.Unmarshal(body, &response); err != nil { + return "", errors.Wrap(err, "cannot parse reveal response body") + } + + // Access the "address" field + return response.RawHex, nil +} diff --git a/zetaclient/chains/bitcoin/observer/inbound.go b/zetaclient/chains/bitcoin/observer/inbound.go index a7dc5afe3d..58000489c2 100644 --- a/zetaclient/chains/bitcoin/observer/inbound.go +++ b/zetaclient/chains/bitcoin/observer/inbound.go @@ -266,7 +266,7 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string, } // #nosec G115 always positive - event, err := GetBtcEvent( + event, err := GetBtcEventWithWitness( ob.btcClient, *tx, tss, @@ -328,7 +328,7 @@ func FilterAndParseIncomingTx( continue // the first tx is coinbase; we do not process coinbase tx } - inbound, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) + inbound, err := GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee) if err != nil { // unable to parse the tx, the caller should retry return nil, errors.Wrapf(err, "error getting btc event for tx %s in block %d", tx.Txid, blockNumber) From 39435742be3f11f6db50a885537f91ed06d60cab Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 16:07:12 +0800 Subject: [PATCH 02/41] test --- e2e/e2etests/e2etests.go | 943 +++++++++--------- .../test_extract_bitcoin_inscription_memo.go | 25 +- 2 files changed, 499 insertions(+), 469 deletions(-) diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index 402eed367e..d3031803e9 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -71,6 +71,7 @@ const ( TestBitcoinWithdrawP2SHName = "bitcoin_withdraw_p2sh" TestBitcoinWithdrawInvalidAddressName = "bitcoin_withdraw_invalid" TestBitcoinWithdrawRestrictedName = "bitcoin_withdraw_restricted" + TestExtractBitcoinInscriptionMemoName = "bitcoin_memo_from_inscription" /* Application tests @@ -118,475 +119,485 @@ const ( TestDeploy = "deploy" ) -// AllE2ETests is an ordered list of all e2e tests -var AllE2ETests = []runner.E2ETest{ - /* - ZETA tests - */ - runner.NewE2ETest( - TestZetaDepositName, - "deposit ZETA from Ethereum to ZEVM", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDeposit, - ), - runner.NewE2ETest( - TestZetaDepositNewAddressName, - "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDepositNewAddress, - ), - runner.NewE2ETest( - TestZetaDepositRestrictedName, - "deposit ZETA from Ethereum to ZEVM restricted address", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDepositRestricted, - ), - runner.NewE2ETest( - TestZetaWithdrawName, - "withdraw ZETA from ZEVM to Ethereum", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, - }, - TestZetaWithdraw, - ), - runner.NewE2ETest( - TestZetaWithdrawBTCRevertName, - "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaWithdrawBTCRevert, - ), - /* - Message passing tests - */ - runner.NewE2ETest( - TestMessagePassingExternalChainsName, - "evm->evm message passing (sending ZETA only)", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, - }, - TestMessagePassingExternalChains, - ), - runner.NewE2ETest( - TestMessagePassingRevertFailExternalChainsName, - "message passing with failing revert between external EVM chains", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, - }, - TestMessagePassingRevertFailExternalChains, - ), - runner.NewE2ETest( - TestMessagePassingRevertSuccessExternalChainsName, - "message passing with successful revert between external EVM chains", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, - }, - TestMessagePassingRevertSuccessExternalChains, - ), - runner.NewE2ETest( - TestMessagePassingEVMtoZEVMName, - "evm -> zevm message passing contract call ", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000009"}, - }, - TestMessagePassingEVMtoZEVM, - ), - runner.NewE2ETest( - TestMessagePassingZEVMToEVMName, - "zevm -> evm message passing contract call", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000007"}, - }, - TestMessagePassingZEVMtoEVM, - ), - runner.NewE2ETest( - TestMessagePassingZEVMtoEVMRevertName, - "zevm -> evm message passing contract call reverts", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000006"}, - }, - TestMessagePassingZEVMtoEVMRevert, - ), - runner.NewE2ETest( - TestMessagePassingEVMtoZEVMRevertName, - "evm -> zevm message passing and revert back to evm", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, - }, - TestMessagePassingEVMtoZEVMRevert, - ), - runner.NewE2ETest( - TestMessagePassingZEVMtoEVMRevertFailName, - "zevm -> evm message passing contract with failing revert", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, - }, - TestMessagePassingZEVMtoEVMRevertFail, - ), - runner.NewE2ETest( - TestMessagePassingEVMtoZEVMRevertFailName, - "evm -> zevm message passing contract with failing revert", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, - }, - TestMessagePassingEVMtoZEVMRevertFail, - ), +//// AllE2ETests is an ordered list of all e2e tests +//var AllE2ETests = []runner.E2ETest{ +// /* +// ZETA tests +// */ +// runner.NewE2ETest( +// TestZetaDepositName, +// "deposit ZETA from Ethereum to ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, +// }, +// TestZetaDeposit, +// ), +// runner.NewE2ETest( +// TestZetaDepositNewAddressName, +// "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, +// }, +// TestZetaDepositNewAddress, +// ), +// runner.NewE2ETest( +// TestZetaDepositRestrictedName, +// "deposit ZETA from Ethereum to ZEVM restricted address", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, +// }, +// TestZetaDepositRestricted, +// ), +// runner.NewE2ETest( +// TestZetaWithdrawName, +// "withdraw ZETA from ZEVM to Ethereum", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, +// }, +// TestZetaWithdraw, +// ), +// runner.NewE2ETest( +// TestZetaWithdrawBTCRevertName, +// "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, +// }, +// TestZetaWithdrawBTCRevert, +// ), +// /* +// Message passing tests +// */ +// runner.NewE2ETest( +// TestMessagePassingExternalChainsName, +// "evm->evm message passing (sending ZETA only)", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, +// }, +// TestMessagePassingExternalChains, +// ), +// runner.NewE2ETest( +// TestMessagePassingRevertFailExternalChainsName, +// "message passing with failing revert between external EVM chains", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, +// }, +// TestMessagePassingRevertFailExternalChains, +// ), +// runner.NewE2ETest( +// TestMessagePassingRevertSuccessExternalChainsName, +// "message passing with successful revert between external EVM chains", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, +// }, +// TestMessagePassingRevertSuccessExternalChains, +// ), +// runner.NewE2ETest( +// TestMessagePassingEVMtoZEVMName, +// "evm -> zevm message passing contract call ", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000009"}, +// }, +// TestMessagePassingEVMtoZEVM, +// ), +// runner.NewE2ETest( +// TestMessagePassingZEVMToEVMName, +// "zevm -> evm message passing contract call", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000007"}, +// }, +// TestMessagePassingZEVMtoEVM, +// ), +// runner.NewE2ETest( +// TestMessagePassingZEVMtoEVMRevertName, +// "zevm -> evm message passing contract call reverts", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000006"}, +// }, +// TestMessagePassingZEVMtoEVMRevert, +// ), +// runner.NewE2ETest( +// TestMessagePassingEVMtoZEVMRevertName, +// "evm -> zevm message passing and revert back to evm", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, +// }, +// TestMessagePassingEVMtoZEVMRevert, +// ), +// runner.NewE2ETest( +// TestMessagePassingZEVMtoEVMRevertFailName, +// "zevm -> evm message passing contract with failing revert", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, +// }, +// TestMessagePassingZEVMtoEVMRevertFail, +// ), +// runner.NewE2ETest( +// TestMessagePassingEVMtoZEVMRevertFailName, +// "evm -> zevm message passing contract with failing revert", +// []runner.ArgDefinition{ +// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, +// }, +// TestMessagePassingEVMtoZEVMRevertFail, +// ), +// +// /* +// EVM gas tests +// */ +// runner.NewE2ETest( +// TestEtherDepositName, +// "deposit Ether into ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "10000000000000000"}, +// }, +// TestEtherDeposit, +// ), +// runner.NewE2ETest( +// TestEtherWithdrawName, +// "withdraw Ether from ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000"}, +// }, +// TestEtherWithdraw, +// ), +// runner.NewE2ETest( +// TestEtherWithdrawRestrictedName, +// "withdraw Ether from ZEVM to restricted address", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000"}, +// }, +// TestEtherWithdrawRestricted, +// ), +// runner.NewE2ETest( +// TestEtherDepositAndCallRefundName, +// "deposit Ether into ZEVM and call a contract that reverts; should refund", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "10000000000000000000"}, +// }, +// TestEtherDepositAndCallRefund, +// ), +// runner.NewE2ETest( +// TestEtherDepositAndCallName, +// "deposit ZRC20 into ZEVM and call a contract", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "1000000000000000000"}, +// }, +// TestEtherDepositAndCall, +// ), +// /* +// EVM erc20 tests +// */ +// runner.NewE2ETest( +// TestERC20WithdrawName, +// "withdraw ERC20 from ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "1000"}, +// }, +// TestERC20Withdraw, +// ), +// runner.NewE2ETest( +// TestERC20DepositName, +// "deposit ERC20 into ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "100000"}, +// }, +// TestERC20Deposit, +// ), +// runner.NewE2ETest( +// TestMultipleERC20DepositName, +// "deposit ERC20 into ZEVM in multiple deposits", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "1000000000"}, +// {Description: "count", DefaultValue: "3"}, +// }, +// TestMultipleERC20Deposit, +// ), +// runner.NewE2ETest( +// TestMultipleERC20WithdrawsName, +// "withdraw ERC20 from ZEVM in multiple withdrawals", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "100"}, +// {Description: "count", DefaultValue: "3"}, +// }, +// TestMultipleERC20Withdraws, +// ), +// runner.NewE2ETest( +// TestERC20DepositRestrictedName, +// "deposit ERC20 into ZEVM restricted address", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "100000"}, +// }, +// TestERC20DepositRestricted, +// ), +// runner.NewE2ETest( +// TestERC20DepositAndCallRefundName, +// "deposit a non-gas ZRC20 into ZEVM and call a contract that reverts", +// []runner.ArgDefinition{}, +// TestERC20DepositAndCallRefund, +// ), +// /* +// Solana tests +// */ +// runner.NewE2ETest( +// TestSolanaDepositName, +// "deposit SOL into ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in lamport", DefaultValue: "13370000"}, +// }, +// TestSolanaDeposit, +// ), +// runner.NewE2ETest( +// TestSolanaWithdrawName, +// "withdraw SOL from ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in lamport", DefaultValue: "1336000"}, +// }, +// TestSolanaWithdraw, +// ), +// /* +// Bitcoin tests +// */ +// runner.NewE2ETest( +// TestBitcoinDepositName, +// "deposit Bitcoin into ZEVM", +// []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinDeposit, +// ), +// runner.NewE2ETest( +// TestBitcoinDepositRefundName, +// "deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.1"}, +// }, +// TestBitcoinDepositRefund, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawSegWitName, +// "withdraw BTC from ZEVM to a SegWit address", +// []runner.ArgDefinition{ +// {Description: "receiver address", DefaultValue: ""}, +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawSegWit, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawTaprootName, +// "withdraw BTC from ZEVM to a Taproot address", +// []runner.ArgDefinition{ +// {Description: "receiver address", DefaultValue: ""}, +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawTaproot, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawLegacyName, +// "withdraw BTC from ZEVM to a legacy address", +// []runner.ArgDefinition{ +// {Description: "receiver address", DefaultValue: ""}, +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawLegacy, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawMultipleName, +// "withdraw BTC from ZEVM multiple times", +// []runner.ArgDefinition{ +// {Description: "amount", DefaultValue: "0.01"}, +// {Description: "times", DefaultValue: "2"}, +// }, +// WithdrawBitcoinMultipleTimes, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawP2WSHName, +// "withdraw BTC from ZEVM to a P2WSH address", +// []runner.ArgDefinition{ +// {Description: "receiver address", DefaultValue: ""}, +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawP2WSH, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawP2SHName, +// "withdraw BTC from ZEVM to a P2SH address", +// []runner.ArgDefinition{ +// {Description: "receiver address", DefaultValue: ""}, +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawP2SH, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawInvalidAddressName, +// "withdraw BTC from ZEVM to an unsupported btc address", +// []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.00001"}, +// }, +// TestBitcoinWithdrawToInvalidAddress, +// ), +// runner.NewE2ETest( +// TestBitcoinWithdrawRestrictedName, +// "withdraw Bitcoin from ZEVM to restricted address", +// []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.001"}, +// }, +// TestBitcoinWithdrawRestricted, +// ), +// /* +// Application tests +// */ +// runner.NewE2ETest( +// TestZRC20SwapName, +// "swap ZRC20 ERC20 for ZRC20 ETH", +// []runner.ArgDefinition{}, +// TestZRC20Swap, +// ), +// runner.NewE2ETest( +// TestCrosschainSwapName, +// "testing Bitcoin ERC20 cross-chain swap", +// []runner.ArgDefinition{}, +// TestCrosschainSwap, +// ), +// /* +// Miscellaneous tests +// */ +// runner.NewE2ETest( +// TestContextUpgradeName, +// "tests sending ETH on ZEVM and check context data using ContextApp", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "1000000000000000"}, +// }, +// TestContextUpgrade, +// ), +// runner.NewE2ETest( +// TestMyTestName, +// "performing custom test", +// []runner.ArgDefinition{}, +// TestMyTest, +// ), +// runner.NewE2ETest( +// TestDonationEtherName, +// "donate Ether to the TSS", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000000000000000"}, +// }, +// TestDonationEther, +// ), +// /* +// Stress tests +// */ +// runner.NewE2ETest( +// TestStressEtherWithdrawName, +// "stress test Ether withdrawal", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000"}, +// {Description: "count", DefaultValue: "100"}, +// }, +// TestStressEtherWithdraw, +// ), +// runner.NewE2ETest( +// TestStressBTCWithdrawName, +// "stress test BTC withdrawal", +// []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.01"}, +// {Description: "count", DefaultValue: "100"}, +// }, +// TestStressBTCWithdraw, +// ), +// runner.NewE2ETest( +// TestStressEtherDepositName, +// "stress test Ether deposit", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000"}, +// {Description: "count", DefaultValue: "100"}, +// }, +// TestStressEtherDeposit, +// ), +// runner.NewE2ETest( +// TestStressBTCDepositName, +// "stress test BTC deposit", +// []runner.ArgDefinition{ +// {Description: "amount in btc", DefaultValue: "0.001"}, +// {Description: "count", DefaultValue: "100"}, +// }, +// TestStressBTCDeposit, +// ), +// /* +// Admin tests +// */ +// runner.NewE2ETest( +// TestWhitelistERC20Name, +// "whitelist a new ERC20 token", +// []runner.ArgDefinition{}, +// TestWhitelistERC20, +// ), +// runner.NewE2ETest( +// TestDepositEtherLiquidityCapName, +// "deposit Ethers into ZEVM with a liquidity cap", +// []runner.ArgDefinition{ +// {Description: "amount in wei", DefaultValue: "100000000000000"}, +// }, +// TestDepositEtherLiquidityCap, +// ), +// runner.NewE2ETest( +// TestMigrateChainSupportName, +// "migrate the evm chain from goerli to sepolia", +// []runner.ArgDefinition{}, +// TestMigrateChainSupport, +// ), +// runner.NewE2ETest( +// TestPauseZRC20Name, +// "pausing ZRC20 on ZetaChain", +// []runner.ArgDefinition{}, +// TestPauseZRC20, +// ), +// runner.NewE2ETest( +// TestUpdateBytecodeZRC20Name, +// "update ZRC20 bytecode swap", +// []runner.ArgDefinition{}, +// TestUpdateBytecodeZRC20, +// ), +// runner.NewE2ETest( +// TestUpdateBytecodeConnectorName, +// "update zevm connector bytecode", +// []runner.ArgDefinition{}, +// TestUpdateBytecodeConnector, +// ), +// runner.NewE2ETest( +// TestRateLimiterName, +// "test sending cctxs with rate limiter enabled and show logs when processing cctxs", +// []runner.ArgDefinition{}, +// TestRateLimiter, +// ), +// runner.NewE2ETest( +// TestCriticalAdminTransactionsName, +// "test critical admin transactions", +// []runner.ArgDefinition{}, +// TestCriticalAdminTransactions, +// ), +// /* +// Special tests +// */ +// runner.NewE2ETest( +// TestDeploy, +// "deploy a contract", +// []runner.ArgDefinition{ +// {Description: "contract name", DefaultValue: ""}, +// }, +// TestDeployContract, +// ), +// runner.NewE2ETest( +// TestMigrateTSSName, +// "migrate TSS funds", +// []runner.ArgDefinition{}, +// TestMigrateTSS, +// ), +//} - /* - EVM gas tests - */ - runner.NewE2ETest( - TestEtherDepositName, - "deposit Ether into ZEVM", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "10000000000000000"}, - }, - TestEtherDeposit, - ), - runner.NewE2ETest( - TestEtherWithdrawName, - "withdraw Ether from ZEVM", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000"}, - }, - TestEtherWithdraw, - ), - runner.NewE2ETest( - TestEtherWithdrawRestrictedName, - "withdraw Ether from ZEVM to restricted address", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000"}, - }, - TestEtherWithdrawRestricted, - ), - runner.NewE2ETest( - TestEtherDepositAndCallRefundName, - "deposit Ether into ZEVM and call a contract that reverts; should refund", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "10000000000000000000"}, - }, - TestEtherDepositAndCallRefund, - ), - runner.NewE2ETest( - TestEtherDepositAndCallName, - "deposit ZRC20 into ZEVM and call a contract", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "1000000000000000000"}, - }, - TestEtherDepositAndCall, - ), - /* - EVM erc20 tests - */ - runner.NewE2ETest( - TestERC20WithdrawName, - "withdraw ERC20 from ZEVM", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "1000"}, - }, - TestERC20Withdraw, - ), - runner.NewE2ETest( - TestERC20DepositName, - "deposit ERC20 into ZEVM", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "100000"}, - }, - TestERC20Deposit, - ), - runner.NewE2ETest( - TestMultipleERC20DepositName, - "deposit ERC20 into ZEVM in multiple deposits", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "1000000000"}, - {Description: "count", DefaultValue: "3"}, - }, - TestMultipleERC20Deposit, - ), - runner.NewE2ETest( - TestMultipleERC20WithdrawsName, - "withdraw ERC20 from ZEVM in multiple withdrawals", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "100"}, - {Description: "count", DefaultValue: "3"}, - }, - TestMultipleERC20Withdraws, - ), - runner.NewE2ETest( - TestERC20DepositRestrictedName, - "deposit ERC20 into ZEVM restricted address", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "100000"}, - }, - TestERC20DepositRestricted, - ), - runner.NewE2ETest( - TestERC20DepositAndCallRefundName, - "deposit a non-gas ZRC20 into ZEVM and call a contract that reverts", - []runner.ArgDefinition{}, - TestERC20DepositAndCallRefund, - ), - /* - Solana tests - */ - runner.NewE2ETest( - TestSolanaDepositName, - "deposit SOL into ZEVM", - []runner.ArgDefinition{ - {Description: "amount in lamport", DefaultValue: "13370000"}, - }, - TestSolanaDeposit, - ), - runner.NewE2ETest( - TestSolanaWithdrawName, - "withdraw SOL from ZEVM", - []runner.ArgDefinition{ - {Description: "amount in lamport", DefaultValue: "1336000"}, - }, - TestSolanaWithdraw, - ), - /* - Bitcoin tests - */ - runner.NewE2ETest( - TestBitcoinDepositName, - "deposit Bitcoin into ZEVM", - []runner.ArgDefinition{ - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinDeposit, - ), +var AllE2ETests = []runner.E2ETest{ runner.NewE2ETest( - TestBitcoinDepositRefundName, - "deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{ + TestExtractBitcoinInscriptionMemoName, + "extract memo from BTC inscription", []runner.ArgDefinition{ {Description: "amount in btc", DefaultValue: "0.1"}, }, - TestBitcoinDepositRefund, - ), - runner.NewE2ETest( - TestBitcoinWithdrawSegWitName, - "withdraw BTC from ZEVM to a SegWit address", - []runner.ArgDefinition{ - {Description: "receiver address", DefaultValue: ""}, - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawSegWit, - ), - runner.NewE2ETest( - TestBitcoinWithdrawTaprootName, - "withdraw BTC from ZEVM to a Taproot address", - []runner.ArgDefinition{ - {Description: "receiver address", DefaultValue: ""}, - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawTaproot, - ), - runner.NewE2ETest( - TestBitcoinWithdrawLegacyName, - "withdraw BTC from ZEVM to a legacy address", - []runner.ArgDefinition{ - {Description: "receiver address", DefaultValue: ""}, - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawLegacy, - ), - runner.NewE2ETest( - TestBitcoinWithdrawMultipleName, - "withdraw BTC from ZEVM multiple times", - []runner.ArgDefinition{ - {Description: "amount", DefaultValue: "0.01"}, - {Description: "times", DefaultValue: "2"}, - }, - WithdrawBitcoinMultipleTimes, - ), - runner.NewE2ETest( - TestBitcoinWithdrawP2WSHName, - "withdraw BTC from ZEVM to a P2WSH address", - []runner.ArgDefinition{ - {Description: "receiver address", DefaultValue: ""}, - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawP2WSH, - ), - runner.NewE2ETest( - TestBitcoinWithdrawP2SHName, - "withdraw BTC from ZEVM to a P2SH address", - []runner.ArgDefinition{ - {Description: "receiver address", DefaultValue: ""}, - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawP2SH, - ), - runner.NewE2ETest( - TestBitcoinWithdrawInvalidAddressName, - "withdraw BTC from ZEVM to an unsupported btc address", - []runner.ArgDefinition{ - {Description: "amount in btc", DefaultValue: "0.00001"}, - }, - TestBitcoinWithdrawToInvalidAddress, - ), - runner.NewE2ETest( - TestBitcoinWithdrawRestrictedName, - "withdraw Bitcoin from ZEVM to restricted address", - []runner.ArgDefinition{ - {Description: "amount in btc", DefaultValue: "0.001"}, - }, - TestBitcoinWithdrawRestricted, - ), - /* - Application tests - */ - runner.NewE2ETest( - TestZRC20SwapName, - "swap ZRC20 ERC20 for ZRC20 ETH", - []runner.ArgDefinition{}, - TestZRC20Swap, - ), - runner.NewE2ETest( - TestCrosschainSwapName, - "testing Bitcoin ERC20 cross-chain swap", - []runner.ArgDefinition{}, - TestCrosschainSwap, - ), - /* - Miscellaneous tests - */ - runner.NewE2ETest( - TestContextUpgradeName, - "tests sending ETH on ZEVM and check context data using ContextApp", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "1000000000000000"}, - }, - TestContextUpgrade, - ), - runner.NewE2ETest( - TestMyTestName, - "performing custom test", - []runner.ArgDefinition{}, - TestMyTest, - ), - runner.NewE2ETest( - TestDonationEtherName, - "donate Ether to the TSS", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000000000000000"}, - }, - TestDonationEther, - ), - /* - Stress tests - */ - runner.NewE2ETest( - TestStressEtherWithdrawName, - "stress test Ether withdrawal", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000"}, - {Description: "count", DefaultValue: "100"}, - }, - TestStressEtherWithdraw, - ), - runner.NewE2ETest( - TestStressBTCWithdrawName, - "stress test BTC withdrawal", - []runner.ArgDefinition{ - {Description: "amount in btc", DefaultValue: "0.01"}, - {Description: "count", DefaultValue: "100"}, - }, - TestStressBTCWithdraw, - ), - runner.NewE2ETest( - TestStressEtherDepositName, - "stress test Ether deposit", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000"}, - {Description: "count", DefaultValue: "100"}, - }, - TestStressEtherDeposit, - ), - runner.NewE2ETest( - TestStressBTCDepositName, - "stress test BTC deposit", - []runner.ArgDefinition{ - {Description: "amount in btc", DefaultValue: "0.001"}, - {Description: "count", DefaultValue: "100"}, - }, - TestStressBTCDeposit, - ), - /* - Admin tests - */ - runner.NewE2ETest( - TestWhitelistERC20Name, - "whitelist a new ERC20 token", - []runner.ArgDefinition{}, - TestWhitelistERC20, - ), - runner.NewE2ETest( - TestDepositEtherLiquidityCapName, - "deposit Ethers into ZEVM with a liquidity cap", - []runner.ArgDefinition{ - {Description: "amount in wei", DefaultValue: "100000000000000"}, - }, - TestDepositEtherLiquidityCap, - ), - runner.NewE2ETest( - TestMigrateChainSupportName, - "migrate the evm chain from goerli to sepolia", - []runner.ArgDefinition{}, - TestMigrateChainSupport, - ), - runner.NewE2ETest( - TestPauseZRC20Name, - "pausing ZRC20 on ZetaChain", - []runner.ArgDefinition{}, - TestPauseZRC20, - ), - runner.NewE2ETest( - TestUpdateBytecodeZRC20Name, - "update ZRC20 bytecode swap", - []runner.ArgDefinition{}, - TestUpdateBytecodeZRC20, - ), - runner.NewE2ETest( - TestUpdateBytecodeConnectorName, - "update zevm connector bytecode", - []runner.ArgDefinition{}, - TestUpdateBytecodeConnector, - ), - runner.NewE2ETest( - TestRateLimiterName, - "test sending cctxs with rate limiter enabled and show logs when processing cctxs", - []runner.ArgDefinition{}, - TestRateLimiter, - ), - runner.NewE2ETest( - TestCriticalAdminTransactionsName, - "test critical admin transactions", - []runner.ArgDefinition{}, - TestCriticalAdminTransactions, - ), - /* - Special tests - */ - runner.NewE2ETest( - TestDeploy, - "deploy a contract", - []runner.ArgDefinition{ - {Description: "contract name", DefaultValue: ""}, - }, - TestDeployContract, - ), - runner.NewE2ETest( - TestMigrateTSSName, - "migrate TSS funds", - []runner.ArgDefinition{}, - TestMigrateTSS, + TestExtractBitcoinInscriptionMemo, ), } diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 500381d7d7..e0fc0f45ec 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -1,6 +1,9 @@ package e2etests import ( + "encoding/hex" + "github.com/btcsuite/btcd/btcjson" + "github.com/rs/zerolog/log" "github.com/stretchr/testify/require" zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin" btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer" @@ -9,13 +12,29 @@ import ( ) func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { - require.Len(r, args, 2) + r.Logger.Info("Testing extract memo from btc inscription") r.SetBtcAddress(r.Name, false) - r.InscribeToTSSFromDeployerWithMemo() - _, err := r.GenerateToAddressIfLocalBitcoin(6, r.BTCDeployerAddress) + // obtain some initial fund + stop := r.MineBlocksIfLocalBitcoin() + defer stop() + + // list deployer utxos + utxos, err := r.ListDeployerUTXOs() + require.NoError(r, err) + + amount := parseFloat(r, args[0]) + memo, _ := hex.DecodeString( + "72f080c854647755d0d9e6f6821f6931f855b9acffd53d87433395672756d58822fd143360762109ab898626556b1c3b8d3096d2361f1297df4a41c1b429471a9aa2fc9be5f27c13b3863d6ac269e4b587d8389f8fd9649859935b0d48dea88cdb40f20c", + ) + + txid, err := r.InscribeToTSSFromDeployerWithMemo(amount, utxos, memo) + require.NoError(r, err) + + _, err = r.GenerateToAddressIfLocalBitcoin(6, r.BTCDeployerAddress) require.NoError(r, err) + gtx, err := r.BtcRPCClient.GetTransaction(txid) require.NoError(r, err) r.Logger.Info("rawtx confirmation: %d", gtx.BlockIndex) From ffaa63c7d679dc377234e040a0bd42c94e2679dd Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 17:07:42 +0800 Subject: [PATCH 03/41] only selected tests --- cmd/zetae2e/local/local.go | 21 +- e2e/e2etests/e2etests.go | 947 ++++++++++++++++++------------------- 2 files changed, 482 insertions(+), 486 deletions(-) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 86adfac7c4..e2e9fc90fe 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -253,12 +253,13 @@ func localE2ETest(cmd *cobra.Command, _ []string) { } bitcoinTests := []string{ - e2etests.TestBitcoinDepositName, - e2etests.TestBitcoinDepositRefundName, - e2etests.TestBitcoinWithdrawSegWitName, - e2etests.TestBitcoinWithdrawInvalidAddressName, - e2etests.TestZetaWithdrawBTCRevertName, - e2etests.TestCrosschainSwapName, + e2etests.TestExtractBitcoinInscriptionMemoName, + //e2etests.TestBitcoinDepositName, + //e2etests.TestBitcoinDepositRefundName, + //e2etests.TestBitcoinWithdrawSegWitName, + //e2etests.TestBitcoinWithdrawInvalidAddressName, + //e2etests.TestZetaWithdrawBTCRevertName, + //e2etests.TestCrosschainSwapName, } bitcoinAdvancedTests := []string{ e2etests.TestBitcoinWithdrawTaprootName, @@ -286,11 +287,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) { ethereumTests = append(ethereumTests, ethereumAdvancedTests...) } - eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...)) - eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...)) - eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...)) + //eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...)) + //eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...)) + //eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...)) eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, bitcoinTests...)) - eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...)) + //eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...)) } if testAdmin { diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index d3031803e9..b2938d6fab 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -1,8 +1,6 @@ package e2etests -import ( - "github.com/zeta-chain/zetacore/e2e/runner" -) +import "github.com/zeta-chain/zetacore/e2e/runner" // List of all e2e test names to be used in zetae2e const ( @@ -119,480 +117,243 @@ const ( TestDeploy = "deploy" ) -//// AllE2ETests is an ordered list of all e2e tests -//var AllE2ETests = []runner.E2ETest{ -// /* -// ZETA tests -// */ -// runner.NewE2ETest( -// TestZetaDepositName, -// "deposit ZETA from Ethereum to ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, -// }, -// TestZetaDeposit, -// ), -// runner.NewE2ETest( -// TestZetaDepositNewAddressName, -// "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, -// }, -// TestZetaDepositNewAddress, -// ), -// runner.NewE2ETest( -// TestZetaDepositRestrictedName, -// "deposit ZETA from Ethereum to ZEVM restricted address", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, -// }, -// TestZetaDepositRestricted, -// ), -// runner.NewE2ETest( -// TestZetaWithdrawName, -// "withdraw ZETA from ZEVM to Ethereum", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, -// }, -// TestZetaWithdraw, -// ), -// runner.NewE2ETest( -// TestZetaWithdrawBTCRevertName, -// "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, -// }, -// TestZetaWithdrawBTCRevert, -// ), -// /* -// Message passing tests -// */ -// runner.NewE2ETest( -// TestMessagePassingExternalChainsName, -// "evm->evm message passing (sending ZETA only)", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, -// }, -// TestMessagePassingExternalChains, -// ), -// runner.NewE2ETest( -// TestMessagePassingRevertFailExternalChainsName, -// "message passing with failing revert between external EVM chains", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, -// }, -// TestMessagePassingRevertFailExternalChains, -// ), -// runner.NewE2ETest( -// TestMessagePassingRevertSuccessExternalChainsName, -// "message passing with successful revert between external EVM chains", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, -// }, -// TestMessagePassingRevertSuccessExternalChains, -// ), -// runner.NewE2ETest( -// TestMessagePassingEVMtoZEVMName, -// "evm -> zevm message passing contract call ", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000009"}, -// }, -// TestMessagePassingEVMtoZEVM, -// ), -// runner.NewE2ETest( -// TestMessagePassingZEVMToEVMName, -// "zevm -> evm message passing contract call", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000007"}, -// }, -// TestMessagePassingZEVMtoEVM, -// ), -// runner.NewE2ETest( -// TestMessagePassingZEVMtoEVMRevertName, -// "zevm -> evm message passing contract call reverts", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000006"}, -// }, -// TestMessagePassingZEVMtoEVMRevert, -// ), -// runner.NewE2ETest( -// TestMessagePassingEVMtoZEVMRevertName, -// "evm -> zevm message passing and revert back to evm", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, -// }, -// TestMessagePassingEVMtoZEVMRevert, -// ), -// runner.NewE2ETest( -// TestMessagePassingZEVMtoEVMRevertFailName, -// "zevm -> evm message passing contract with failing revert", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, -// }, -// TestMessagePassingZEVMtoEVMRevertFail, -// ), -// runner.NewE2ETest( -// TestMessagePassingEVMtoZEVMRevertFailName, -// "evm -> zevm message passing contract with failing revert", -// []runner.ArgDefinition{ -// {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, -// }, -// TestMessagePassingEVMtoZEVMRevertFail, -// ), -// -// /* -// EVM gas tests -// */ -// runner.NewE2ETest( -// TestEtherDepositName, -// "deposit Ether into ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "10000000000000000"}, -// }, -// TestEtherDeposit, -// ), -// runner.NewE2ETest( -// TestEtherWithdrawName, -// "withdraw Ether from ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000"}, -// }, -// TestEtherWithdraw, -// ), -// runner.NewE2ETest( -// TestEtherWithdrawRestrictedName, -// "withdraw Ether from ZEVM to restricted address", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000"}, -// }, -// TestEtherWithdrawRestricted, -// ), -// runner.NewE2ETest( -// TestEtherDepositAndCallRefundName, -// "deposit Ether into ZEVM and call a contract that reverts; should refund", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "10000000000000000000"}, -// }, -// TestEtherDepositAndCallRefund, -// ), -// runner.NewE2ETest( -// TestEtherDepositAndCallName, -// "deposit ZRC20 into ZEVM and call a contract", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "1000000000000000000"}, -// }, -// TestEtherDepositAndCall, -// ), -// /* -// EVM erc20 tests -// */ -// runner.NewE2ETest( -// TestERC20WithdrawName, -// "withdraw ERC20 from ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "1000"}, -// }, -// TestERC20Withdraw, -// ), -// runner.NewE2ETest( -// TestERC20DepositName, -// "deposit ERC20 into ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "100000"}, -// }, -// TestERC20Deposit, -// ), -// runner.NewE2ETest( -// TestMultipleERC20DepositName, -// "deposit ERC20 into ZEVM in multiple deposits", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "1000000000"}, -// {Description: "count", DefaultValue: "3"}, -// }, -// TestMultipleERC20Deposit, -// ), -// runner.NewE2ETest( -// TestMultipleERC20WithdrawsName, -// "withdraw ERC20 from ZEVM in multiple withdrawals", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "100"}, -// {Description: "count", DefaultValue: "3"}, -// }, -// TestMultipleERC20Withdraws, -// ), -// runner.NewE2ETest( -// TestERC20DepositRestrictedName, -// "deposit ERC20 into ZEVM restricted address", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "100000"}, -// }, -// TestERC20DepositRestricted, -// ), -// runner.NewE2ETest( -// TestERC20DepositAndCallRefundName, -// "deposit a non-gas ZRC20 into ZEVM and call a contract that reverts", -// []runner.ArgDefinition{}, -// TestERC20DepositAndCallRefund, -// ), -// /* -// Solana tests -// */ -// runner.NewE2ETest( -// TestSolanaDepositName, -// "deposit SOL into ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in lamport", DefaultValue: "13370000"}, -// }, -// TestSolanaDeposit, -// ), -// runner.NewE2ETest( -// TestSolanaWithdrawName, -// "withdraw SOL from ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in lamport", DefaultValue: "1336000"}, -// }, -// TestSolanaWithdraw, -// ), -// /* -// Bitcoin tests -// */ -// runner.NewE2ETest( -// TestBitcoinDepositName, -// "deposit Bitcoin into ZEVM", -// []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinDeposit, -// ), -// runner.NewE2ETest( -// TestBitcoinDepositRefundName, -// "deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.1"}, -// }, -// TestBitcoinDepositRefund, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawSegWitName, -// "withdraw BTC from ZEVM to a SegWit address", -// []runner.ArgDefinition{ -// {Description: "receiver address", DefaultValue: ""}, -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawSegWit, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawTaprootName, -// "withdraw BTC from ZEVM to a Taproot address", -// []runner.ArgDefinition{ -// {Description: "receiver address", DefaultValue: ""}, -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawTaproot, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawLegacyName, -// "withdraw BTC from ZEVM to a legacy address", -// []runner.ArgDefinition{ -// {Description: "receiver address", DefaultValue: ""}, -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawLegacy, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawMultipleName, -// "withdraw BTC from ZEVM multiple times", -// []runner.ArgDefinition{ -// {Description: "amount", DefaultValue: "0.01"}, -// {Description: "times", DefaultValue: "2"}, -// }, -// WithdrawBitcoinMultipleTimes, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawP2WSHName, -// "withdraw BTC from ZEVM to a P2WSH address", -// []runner.ArgDefinition{ -// {Description: "receiver address", DefaultValue: ""}, -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawP2WSH, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawP2SHName, -// "withdraw BTC from ZEVM to a P2SH address", -// []runner.ArgDefinition{ -// {Description: "receiver address", DefaultValue: ""}, -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawP2SH, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawInvalidAddressName, -// "withdraw BTC from ZEVM to an unsupported btc address", -// []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.00001"}, -// }, -// TestBitcoinWithdrawToInvalidAddress, -// ), -// runner.NewE2ETest( -// TestBitcoinWithdrawRestrictedName, -// "withdraw Bitcoin from ZEVM to restricted address", -// []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.001"}, -// }, -// TestBitcoinWithdrawRestricted, -// ), -// /* -// Application tests -// */ -// runner.NewE2ETest( -// TestZRC20SwapName, -// "swap ZRC20 ERC20 for ZRC20 ETH", -// []runner.ArgDefinition{}, -// TestZRC20Swap, -// ), -// runner.NewE2ETest( -// TestCrosschainSwapName, -// "testing Bitcoin ERC20 cross-chain swap", -// []runner.ArgDefinition{}, -// TestCrosschainSwap, -// ), -// /* -// Miscellaneous tests -// */ -// runner.NewE2ETest( -// TestContextUpgradeName, -// "tests sending ETH on ZEVM and check context data using ContextApp", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "1000000000000000"}, -// }, -// TestContextUpgrade, -// ), -// runner.NewE2ETest( -// TestMyTestName, -// "performing custom test", -// []runner.ArgDefinition{}, -// TestMyTest, -// ), -// runner.NewE2ETest( -// TestDonationEtherName, -// "donate Ether to the TSS", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000000000000000"}, -// }, -// TestDonationEther, -// ), -// /* -// Stress tests -// */ -// runner.NewE2ETest( -// TestStressEtherWithdrawName, -// "stress test Ether withdrawal", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000"}, -// {Description: "count", DefaultValue: "100"}, -// }, -// TestStressEtherWithdraw, -// ), -// runner.NewE2ETest( -// TestStressBTCWithdrawName, -// "stress test BTC withdrawal", -// []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.01"}, -// {Description: "count", DefaultValue: "100"}, -// }, -// TestStressBTCWithdraw, -// ), -// runner.NewE2ETest( -// TestStressEtherDepositName, -// "stress test Ether deposit", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000"}, -// {Description: "count", DefaultValue: "100"}, -// }, -// TestStressEtherDeposit, -// ), -// runner.NewE2ETest( -// TestStressBTCDepositName, -// "stress test BTC deposit", -// []runner.ArgDefinition{ -// {Description: "amount in btc", DefaultValue: "0.001"}, -// {Description: "count", DefaultValue: "100"}, -// }, -// TestStressBTCDeposit, -// ), -// /* -// Admin tests -// */ -// runner.NewE2ETest( -// TestWhitelistERC20Name, -// "whitelist a new ERC20 token", -// []runner.ArgDefinition{}, -// TestWhitelistERC20, -// ), -// runner.NewE2ETest( -// TestDepositEtherLiquidityCapName, -// "deposit Ethers into ZEVM with a liquidity cap", -// []runner.ArgDefinition{ -// {Description: "amount in wei", DefaultValue: "100000000000000"}, -// }, -// TestDepositEtherLiquidityCap, -// ), -// runner.NewE2ETest( -// TestMigrateChainSupportName, -// "migrate the evm chain from goerli to sepolia", -// []runner.ArgDefinition{}, -// TestMigrateChainSupport, -// ), -// runner.NewE2ETest( -// TestPauseZRC20Name, -// "pausing ZRC20 on ZetaChain", -// []runner.ArgDefinition{}, -// TestPauseZRC20, -// ), -// runner.NewE2ETest( -// TestUpdateBytecodeZRC20Name, -// "update ZRC20 bytecode swap", -// []runner.ArgDefinition{}, -// TestUpdateBytecodeZRC20, -// ), -// runner.NewE2ETest( -// TestUpdateBytecodeConnectorName, -// "update zevm connector bytecode", -// []runner.ArgDefinition{}, -// TestUpdateBytecodeConnector, -// ), -// runner.NewE2ETest( -// TestRateLimiterName, -// "test sending cctxs with rate limiter enabled and show logs when processing cctxs", -// []runner.ArgDefinition{}, -// TestRateLimiter, -// ), -// runner.NewE2ETest( -// TestCriticalAdminTransactionsName, -// "test critical admin transactions", -// []runner.ArgDefinition{}, -// TestCriticalAdminTransactions, -// ), -// /* -// Special tests -// */ -// runner.NewE2ETest( -// TestDeploy, -// "deploy a contract", -// []runner.ArgDefinition{ -// {Description: "contract name", DefaultValue: ""}, -// }, -// TestDeployContract, -// ), -// runner.NewE2ETest( -// TestMigrateTSSName, -// "migrate TSS funds", -// []runner.ArgDefinition{}, -// TestMigrateTSS, -// ), -//} - +// AllE2ETests is an ordered list of all e2e tests var AllE2ETests = []runner.E2ETest{ + /* + ZETA tests + */ + runner.NewE2ETest( + TestZetaDepositName, + "deposit ZETA from Ethereum to ZEVM", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + TestZetaDeposit, + ), + runner.NewE2ETest( + TestZetaDepositNewAddressName, + "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + TestZetaDepositNewAddress, + ), + runner.NewE2ETest( + TestZetaDepositRestrictedName, + "deposit ZETA from Ethereum to ZEVM restricted address", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + TestZetaDepositRestricted, + ), + runner.NewE2ETest( + TestZetaWithdrawName, + "withdraw ZETA from ZEVM to Ethereum", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestZetaWithdraw, + ), + runner.NewE2ETest( + TestZetaWithdrawBTCRevertName, + "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + TestZetaWithdrawBTCRevert, + ), + /* + Message passing tests + */ + runner.NewE2ETest( + TestMessagePassingExternalChainsName, + "evm->evm message passing (sending ZETA only)", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestMessagePassingExternalChains, + ), + runner.NewE2ETest( + TestMessagePassingRevertFailExternalChainsName, + "message passing with failing revert between external EVM chains", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestMessagePassingRevertFailExternalChains, + ), + runner.NewE2ETest( + TestMessagePassingRevertSuccessExternalChainsName, + "message passing with successful revert between external EVM chains", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + TestMessagePassingRevertSuccessExternalChains, + ), + runner.NewE2ETest( + TestMessagePassingEVMtoZEVMName, + "evm -> zevm message passing contract call ", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000009"}, + }, + TestMessagePassingEVMtoZEVM, + ), + runner.NewE2ETest( + TestMessagePassingZEVMToEVMName, + "zevm -> evm message passing contract call", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000007"}, + }, + TestMessagePassingZEVMtoEVM, + ), + runner.NewE2ETest( + TestMessagePassingZEVMtoEVMRevertName, + "zevm -> evm message passing contract call reverts", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000006"}, + }, + TestMessagePassingZEVMtoEVMRevert, + ), + runner.NewE2ETest( + TestMessagePassingEVMtoZEVMRevertName, + "evm -> zevm message passing and revert back to evm", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, + }, + TestMessagePassingEVMtoZEVMRevert, + ), + runner.NewE2ETest( + TestMessagePassingZEVMtoEVMRevertFailName, + "zevm -> evm message passing contract with failing revert", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, + }, + TestMessagePassingZEVMtoEVMRevertFail, + ), + runner.NewE2ETest( + TestMessagePassingEVMtoZEVMRevertFailName, + "evm -> zevm message passing contract with failing revert", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000008"}, + }, + TestMessagePassingEVMtoZEVMRevertFail, + ), + + /* + EVM gas tests + */ + runner.NewE2ETest( + TestEtherDepositName, + "deposit Ether into ZEVM", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "10000000000000000"}, + }, + TestEtherDeposit, + ), + runner.NewE2ETest( + TestEtherWithdrawName, + "withdraw Ether from ZEVM", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000"}, + }, + TestEtherWithdraw, + ), + runner.NewE2ETest( + TestEtherWithdrawRestrictedName, + "withdraw Ether from ZEVM to restricted address", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000"}, + }, + TestEtherWithdrawRestricted, + ), + runner.NewE2ETest( + TestEtherDepositAndCallRefundName, + "deposit Ether into ZEVM and call a contract that reverts; should refund", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "10000000000000000000"}, + }, + TestEtherDepositAndCallRefund, + ), + runner.NewE2ETest( + TestEtherDepositAndCallName, + "deposit ZRC20 into ZEVM and call a contract", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "1000000000000000000"}, + }, + TestEtherDepositAndCall, + ), + /* + EVM erc20 tests + */ + runner.NewE2ETest( + TestERC20WithdrawName, + "withdraw ERC20 from ZEVM", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "1000"}, + }, + TestERC20Withdraw, + ), + runner.NewE2ETest( + TestERC20DepositName, + "deposit ERC20 into ZEVM", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "100000"}, + }, + TestERC20Deposit, + ), + runner.NewE2ETest( + TestMultipleERC20DepositName, + "deposit ERC20 into ZEVM in multiple deposits", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "1000000000"}, + {Description: "count", DefaultValue: "3"}, + }, + TestMultipleERC20Deposit, + ), + runner.NewE2ETest( + TestMultipleERC20WithdrawsName, + "withdraw ERC20 from ZEVM in multiple withdrawals", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "100"}, + {Description: "count", DefaultValue: "3"}, + }, + TestMultipleERC20Withdraws, + ), + runner.NewE2ETest( + TestERC20DepositRestrictedName, + "deposit ERC20 into ZEVM restricted address", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "100000"}, + }, + TestERC20DepositRestricted, + ), + runner.NewE2ETest( + TestERC20DepositAndCallRefundName, + "deposit a non-gas ZRC20 into ZEVM and call a contract that reverts", + []runner.ArgDefinition{}, + TestERC20DepositAndCallRefund, + ), + /* + Solana tests + */ + runner.NewE2ETest( + TestSolanaDepositName, + "deposit SOL into ZEVM", + []runner.ArgDefinition{ + {Description: "amount in lamport", DefaultValue: "13370000"}, + }, + TestSolanaDeposit, + ), + runner.NewE2ETest( + TestSolanaWithdrawName, + "withdraw SOL from ZEVM", + []runner.ArgDefinition{ + {Description: "amount in lamport", DefaultValue: "1336000"}, + }, + TestSolanaWithdraw, + ), + /* + Bitcoin tests + */ runner.NewE2ETest( TestExtractBitcoinInscriptionMemoName, "extract memo from BTC inscription", []runner.ArgDefinition{ @@ -600,4 +361,238 @@ var AllE2ETests = []runner.E2ETest{ }, TestExtractBitcoinInscriptionMemo, ), + runner.NewE2ETest( + TestBitcoinDepositName, + "deposit Bitcoin into ZEVM", + []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinDeposit, + ), + runner.NewE2ETest( + TestBitcoinDepositRefundName, + "deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.1"}, + }, + TestBitcoinDepositRefund, + ), + runner.NewE2ETest( + TestBitcoinWithdrawSegWitName, + "withdraw BTC from ZEVM to a SegWit address", + []runner.ArgDefinition{ + {Description: "receiver address", DefaultValue: ""}, + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawSegWit, + ), + runner.NewE2ETest( + TestBitcoinWithdrawTaprootName, + "withdraw BTC from ZEVM to a Taproot address", + []runner.ArgDefinition{ + {Description: "receiver address", DefaultValue: ""}, + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawTaproot, + ), + runner.NewE2ETest( + TestBitcoinWithdrawLegacyName, + "withdraw BTC from ZEVM to a legacy address", + []runner.ArgDefinition{ + {Description: "receiver address", DefaultValue: ""}, + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawLegacy, + ), + runner.NewE2ETest( + TestBitcoinWithdrawMultipleName, + "withdraw BTC from ZEVM multiple times", + []runner.ArgDefinition{ + {Description: "amount", DefaultValue: "0.01"}, + {Description: "times", DefaultValue: "2"}, + }, + WithdrawBitcoinMultipleTimes, + ), + runner.NewE2ETest( + TestBitcoinWithdrawP2WSHName, + "withdraw BTC from ZEVM to a P2WSH address", + []runner.ArgDefinition{ + {Description: "receiver address", DefaultValue: ""}, + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawP2WSH, + ), + runner.NewE2ETest( + TestBitcoinWithdrawP2SHName, + "withdraw BTC from ZEVM to a P2SH address", + []runner.ArgDefinition{ + {Description: "receiver address", DefaultValue: ""}, + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawP2SH, + ), + runner.NewE2ETest( + TestBitcoinWithdrawInvalidAddressName, + "withdraw BTC from ZEVM to an unsupported btc address", + []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.00001"}, + }, + TestBitcoinWithdrawToInvalidAddress, + ), + runner.NewE2ETest( + TestBitcoinWithdrawRestrictedName, + "withdraw Bitcoin from ZEVM to restricted address", + []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.001"}, + }, + TestBitcoinWithdrawRestricted, + ), + /* + Application tests + */ + runner.NewE2ETest( + TestZRC20SwapName, + "swap ZRC20 ERC20 for ZRC20 ETH", + []runner.ArgDefinition{}, + TestZRC20Swap, + ), + runner.NewE2ETest( + TestCrosschainSwapName, + "testing Bitcoin ERC20 cross-chain swap", + []runner.ArgDefinition{}, + TestCrosschainSwap, + ), + /* + Miscellaneous tests + */ + runner.NewE2ETest( + TestContextUpgradeName, + "tests sending ETH on ZEVM and check context data using ContextApp", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "1000000000000000"}, + }, + TestContextUpgrade, + ), + runner.NewE2ETest( + TestMyTestName, + "performing custom test", + []runner.ArgDefinition{}, + TestMyTest, + ), + runner.NewE2ETest( + TestDonationEtherName, + "donate Ether to the TSS", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000000000000000"}, + }, + TestDonationEther, + ), + /* + Stress tests + */ + runner.NewE2ETest( + TestStressEtherWithdrawName, + "stress test Ether withdrawal", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000"}, + {Description: "count", DefaultValue: "100"}, + }, + TestStressEtherWithdraw, + ), + runner.NewE2ETest( + TestStressBTCWithdrawName, + "stress test BTC withdrawal", + []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.01"}, + {Description: "count", DefaultValue: "100"}, + }, + TestStressBTCWithdraw, + ), + runner.NewE2ETest( + TestStressEtherDepositName, + "stress test Ether deposit", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000"}, + {Description: "count", DefaultValue: "100"}, + }, + TestStressEtherDeposit, + ), + runner.NewE2ETest( + TestStressBTCDepositName, + "stress test BTC deposit", + []runner.ArgDefinition{ + {Description: "amount in btc", DefaultValue: "0.001"}, + {Description: "count", DefaultValue: "100"}, + }, + TestStressBTCDeposit, + ), + /* + Admin tests + */ + runner.NewE2ETest( + TestWhitelistERC20Name, + "whitelist a new ERC20 token", + []runner.ArgDefinition{}, + TestWhitelistERC20, + ), + runner.NewE2ETest( + TestDepositEtherLiquidityCapName, + "deposit Ethers into ZEVM with a liquidity cap", + []runner.ArgDefinition{ + {Description: "amount in wei", DefaultValue: "100000000000000"}, + }, + TestDepositEtherLiquidityCap, + ), + runner.NewE2ETest( + TestMigrateChainSupportName, + "migrate the evm chain from goerli to sepolia", + []runner.ArgDefinition{}, + TestMigrateChainSupport, + ), + runner.NewE2ETest( + TestPauseZRC20Name, + "pausing ZRC20 on ZetaChain", + []runner.ArgDefinition{}, + TestPauseZRC20, + ), + runner.NewE2ETest( + TestUpdateBytecodeZRC20Name, + "update ZRC20 bytecode swap", + []runner.ArgDefinition{}, + TestUpdateBytecodeZRC20, + ), + runner.NewE2ETest( + TestUpdateBytecodeConnectorName, + "update zevm connector bytecode", + []runner.ArgDefinition{}, + TestUpdateBytecodeConnector, + ), + runner.NewE2ETest( + TestRateLimiterName, + "test sending cctxs with rate limiter enabled and show logs when processing cctxs", + []runner.ArgDefinition{}, + TestRateLimiter, + ), + runner.NewE2ETest( + TestCriticalAdminTransactionsName, + "test critical admin transactions", + []runner.ArgDefinition{}, + TestCriticalAdminTransactions, + ), + /* + Special tests + */ + runner.NewE2ETest( + TestDeploy, + "deploy a contract", + []runner.ArgDefinition{ + {Description: "contract name", DefaultValue: ""}, + }, + TestDeployContract, + ), + runner.NewE2ETest( + TestMigrateTSSName, + "migrate TSS funds", + []runner.ArgDefinition{}, + TestMigrateTSS, + ), } From 8405c859c0e0ba4d8e7d624c20f74a3c11ae1f8d Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 17:20:15 +0800 Subject: [PATCH 04/41] add tests --- cmd/zetae2e/local/bitcoin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 184277d0cc..6a8532c69b 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -61,6 +61,8 @@ func bitcoinTestRoutine( return fmt.Errorf("bitcoin tests failed: %v", err) } + bitcoinRunner.Logger.Print("Running tests:", testNames) + if err := bitcoinRunner.RunE2ETests(testsToRun); err != nil { return fmt.Errorf("bitcoin tests failed: %v", err) } From 4aee79787008dda273aff24add14fc83a57ee242 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 20:34:32 +0800 Subject: [PATCH 05/41] update url --- contrib/localnet/bitcoin-sidecar/js/src/client.ts | 8 ++++---- contrib/localnet/bitcoin-sidecar/js/src/index.ts | 4 ++-- e2e/runner/bitcoin.go | 4 ++-- e2e/runner/inscription.go | 4 +++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts index 514ddfe043..4c76e6b2af 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/client.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -103,12 +103,12 @@ export class ZetaBtcClient { return commitAddress; } - public buildRevealTxn(commitTxn: BtcInput, commitAmount: number, feeRate: number): Buffer { + public buildRevealTxn(to: string, commitTxn: BtcInput, commitAmount: number, feeRate: number): Buffer { if (this.reveal === null) { throw new Error("commit txn not built yet"); } - this.reveal.with_commit_tx(commitTxn, commitAmount, feeRate); + this.reveal.with_commit_tx(to, commitTxn, commitAmount, feeRate); return this.reveal.dump(); } @@ -132,7 +132,7 @@ class RevealTxnBuilder { this.network = network; } - public with_commit_tx(commitTxn: BtcInput, commitAmount: number, feeRate: number): RevealTxnBuilder { + public with_commit_tx(to: string, commitTxn: BtcInput, commitAmount: number, feeRate: number): RevealTxnBuilder { const scriptTree: Taptree = { output: this.leafScript }; const { output, witness } = payments.p2tr({ @@ -160,7 +160,7 @@ class RevealTxnBuilder { this.psbt.addOutput({ value: commitAmount - this.estimateFee(commitAmount, feeRate), - address: this.tssAddress(), + address: to, }); this.psbt.signAllInputs(this.key); diff --git a/contrib/localnet/bitcoin-sidecar/js/src/index.ts b/contrib/localnet/bitcoin-sidecar/js/src/index.ts index b2686fa06c..160e4e742d 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/index.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/index.ts @@ -22,10 +22,10 @@ app.post('/commit', (req: Request, res: Response) => { // Route to handle URL-encoded POST requests app.post('/reveal', (req: Request, res: Response) => { - const { txn, idx, amount, feeRate } = req.body; + const { txn, idx, amount, feeRate, to } = req.body; console.log(txn, idx, amount, feeRate); - const rawHex = zetaClient.buildRevealTxn({ txn, idx }, Number(amount), feeRate).toString("hex"); + const rawHex = zetaClient.buildRevealTxn(to,{ txn, idx }, Number(amount), feeRate).toString("hex"); zetaClient = ZetaBtcClient.regtest(); res.json({ rawHex }); }); diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 3380845a7b..00bc2143d5 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -301,7 +301,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( inputUTXOs []btcjson.ListUnspentResult, memo []byte, ) (*chainhash.Hash, error) { - builder := InscriptionBuilder{sidecarUrl: "http://localhost:8000", client: http.Client{}} + builder := InscriptionBuilder{sidecarUrl: "http://bitcoin-node-sidecar:8000", client: http.Client{}} address, err := builder.GenerateCommitAddress(memo) if err != nil { @@ -315,7 +315,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( // sendToTSSFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 - hexTx, err := builder.GenerateRevealTxn(txnHash.String(), outpointIdx, amount) + hexTx, err := builder.GenerateRevealTxn(r.TSSAddress.String(), txnHash.String(), outpointIdx, amount) if err != nil { return nil, err } diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 4feb34c587..7c1b6b254c 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -24,6 +24,7 @@ type revealRequest struct { Idx int `json:"idx"` Amount int `json:"amount"` FeeRate int `json:"feeRate"` + To string `json:"to"` } // InscriptionBuilder is a util struct that help create inscription commit and reveal transactions @@ -73,12 +74,13 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (btcutil.Address return btcutil.DecodeAddress(response.Address, &chaincfg.RegressionNetParams) } -func (r *InscriptionBuilder) GenerateRevealTxn(txnHash string, idx int, amount float64) (string, error) { +func (r *InscriptionBuilder) GenerateRevealTxn(to string, txnHash string, idx int, amount float64) (string, error) { postData := revealRequest{ Txn: txnHash, Idx: idx, Amount: int(amount * 100000000), FeeRate: 10, + To: to, } // Convert the payload to JSON From a7db462f596d9ebd58d5199b9959d3f81a5fce69 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 20:57:58 +0800 Subject: [PATCH 06/41] more logs --- e2e/runner/bitcoin.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 00bc2143d5..262b1c2e6c 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -307,11 +307,13 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } + log.Logger.Print("received inscription commit address", address) txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, address, inputUTXOs, memo) if err != nil { return nil, err } + log.Logger.Print("obtained inscription commit txn hash", txnHash.String()) // sendToTSSFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 @@ -319,6 +321,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } + log.Logger.Print("obtained inscription reveal txn", hexTx) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) @@ -331,6 +334,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { return nil, err } + log.Logger.Print("recovered inscription reveal txn", hexTx) txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) require.NoError(r, err) From 73c66956e0451d9b2697b0217ce06ada328f0418 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 21:21:46 +0800 Subject: [PATCH 07/41] more logs --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 3 ++- e2e/runner/bitcoin.go | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index e0fc0f45ec..b88f760945 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -12,13 +12,14 @@ import ( ) func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { - r.Logger.Info("Testing extract memo from btc inscription") + r.Logger.Print("Testing extract memo from btc inscription") r.SetBtcAddress(r.Name, false) // obtain some initial fund stop := r.MineBlocksIfLocalBitcoin() defer stop() + r.Logger.Print("Mined blocks") // list deployer utxos utxos, err := r.ListDeployerUTXOs() diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 262b1c2e6c..0cee67b9a7 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -307,13 +307,13 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - log.Logger.Print("received inscription commit address", address) + r.Logger.Print("received inscription commit address", address) txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, address, inputUTXOs, memo) if err != nil { return nil, err } - log.Logger.Print("obtained inscription commit txn hash", txnHash.String()) + r.Logger.Print("obtained inscription commit txn hash", txnHash.String()) // sendToTSSFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 @@ -321,7 +321,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - log.Logger.Print("obtained inscription reveal txn", hexTx) + r.Logger.Print("obtained inscription reveal txn", hexTx) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) @@ -334,7 +334,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { return nil, err } - log.Logger.Print("recovered inscription reveal txn", hexTx) + r.Logger.Print("recovered inscription reveal txn", hexTx) txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) require.NoError(r, err) From cb60c4e3c38ec71d9bfecdfd7cca63a23c2b3387 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 21:49:25 +0800 Subject: [PATCH 08/41] update --- e2e/runner/bitcoin.go | 8 +++++++- e2e/runner/inscription.go | 16 +++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 0cee67b9a7..717cabb14a 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/btcsuite/btcd/chaincfg" "net/http" "sort" "time" @@ -309,7 +310,12 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( } r.Logger.Print("received inscription commit address", address) - txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, address, inputUTXOs, memo) + decodedAddress, err := btcutil.DecodeAddress(address, &chaincfg.RegressionNetParams) + if err != nil { + return nil, err + } + + txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, decodedAddress, inputUTXOs, memo) if err != nil { return nil, err } diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 7c1b6b254c..6df0399722 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/hex" "encoding/json" - "github.com/btcsuite/btcd/chaincfg" - "github.com/btcsuite/btcutil" "github.com/pkg/errors" "io" "net/http" @@ -33,7 +31,7 @@ type InscriptionBuilder struct { client http.Client } -func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (btcutil.Address, error) { +func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) { // Create the payload postData := map[string]string{ "memo": hex.EncodeToString(memo), @@ -42,36 +40,36 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (btcutil.Address // Convert the payload to JSON jsonData, err := json.Marshal(postData) if err != nil { - return nil, err + return "", err } postUrl := r.sidecarUrl + "/commit" req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) if err != nil { - return nil, errors.Wrap(err, "cannot create commit request") + return "", errors.Wrap(err, "cannot create commit request") } req.Header.Set("Content-Type", "application/json") // Send the request resp, err := r.client.Do(req) if err != nil { - return nil, errors.Wrap(err, "cannot send to sidecar") + return "", errors.Wrap(err, "cannot send to sidecar") } defer resp.Body.Close() // Read the response body body, err := io.ReadAll(resp.Body) if err != nil { - return nil, errors.Wrap(err, "cannot read commit response body") + return "", errors.Wrap(err, "cannot read commit response body") } // Parse the JSON response var response commitResponse if err := json.Unmarshal(body, &response); err != nil { - return nil, errors.Wrap(err, "cannot parse commit response body") + return "", errors.Wrap(err, "cannot parse commit response body") } - return btcutil.DecodeAddress(response.Address, &chaincfg.RegressionNetParams) + return response.Address, nil } func (r *InscriptionBuilder) GenerateRevealTxn(to string, txnHash string, idx int, amount float64) (string, error) { From a43f6ec15fd9ac9c0e447af6e3bde3ab9dfe8722 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 22:04:09 +0800 Subject: [PATCH 09/41] logs --- e2e/runner/inscription.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 6df0399722..8442e41a9a 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "fmt" "github.com/pkg/errors" "io" "net/http" @@ -68,6 +69,7 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) if err := json.Unmarshal(body, &response); err != nil { return "", errors.Wrap(err, "cannot parse commit response body") } + fmt.Print("raw commit response", response) return response.Address, nil } From 58d51d27f46c5875a27014c196687abad9642a4c Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 22:26:27 +0800 Subject: [PATCH 10/41] handle json --- e2e/runner/inscription.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 8442e41a9a..ea94f198b0 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -59,16 +59,12 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) defer resp.Body.Close() // Read the response body - body, err := io.ReadAll(resp.Body) + var response commitResponse + err := json.NewDecoder(resp.Body).Decode(&response) if err != nil { - return "", errors.Wrap(err, "cannot read commit response body") + return "", err } - // Parse the JSON response - var response commitResponse - if err := json.Unmarshal(body, &response); err != nil { - return "", errors.Wrap(err, "cannot parse commit response body") - } fmt.Print("raw commit response", response) return response.Address, nil From cb59e0b517eb8db17dba33e47a0cadadfba65e99 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 15 Aug 2024 22:30:11 +0800 Subject: [PATCH 11/41] handle json --- e2e/runner/inscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index ea94f198b0..be27d8ab88 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -60,7 +60,7 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) // Read the response body var response commitResponse - err := json.NewDecoder(resp.Body).Decode(&response) + err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { return "", err } From a0c0ab10ee174b622284e476ee237d221d0a942f Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 09:26:32 +0800 Subject: [PATCH 12/41] parse p2tr --- e2e/runner/bitcoin.go | 7 +++---- e2e/runner/inscription.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 717cabb14a..e5af3ef5cb 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/hex" "fmt" - "github.com/btcsuite/btcd/chaincfg" "net/http" "sort" "time" @@ -308,14 +307,14 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - r.Logger.Print("received inscription commit address", address) + r.Logger.Print("received inscription commit address %s", address) - decodedAddress, err := btcutil.DecodeAddress(address, &chaincfg.RegressionNetParams) + receiver, err := chains.DecodeBtcAddress(address, r.GetBitcoinChainID()) if err != nil { return nil, err } - txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, decodedAddress, inputUTXOs, memo) + txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, receiver, inputUTXOs, memo) if err != nil { return nil, err } diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index be27d8ab88..656e4acc58 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -65,7 +65,7 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) return "", err } - fmt.Print("raw commit response", response) + fmt.Print("raw commit response ", response.Address) return response.Address, nil } From f4081861c3f11e2e2ccc3a242b24dd444c278780 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 09:37:20 +0800 Subject: [PATCH 13/41] update memo --- e2e/runner/bitcoin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index e5af3ef5cb..df0edc6703 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -179,10 +179,10 @@ func (r *E2ERunner) SendToTSSFromDeployerWithMemo( inputUTXOs []btcjson.ListUnspentResult, memo []byte, ) (*chainhash.Hash, error) { - return r.sendToTSSFromDeployerWithMemo(amount, r.BTCTSSAddress, inputUTXOs, memo) + return r.sendToAddrFromDeployerWithMemo(amount, r.BTCTSSAddress, inputUTXOs, memo) } -func (r *E2ERunner) sendToTSSFromDeployerWithMemo( +func (r *E2ERunner) sendToAddrFromDeployerWithMemo( amount float64, to btcutil.Address, inputUTXOs []btcjson.ListUnspentResult, @@ -314,13 +314,13 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( return nil, err } - txnHash, err := r.sendToTSSFromDeployerWithMemo(amount, receiver, inputUTXOs, memo) + txnHash, err := r.sendToAddrFromDeployerWithMemo(amount, receiver, inputUTXOs, []byte(constant.DonationMessage)) if err != nil { return nil, err } r.Logger.Print("obtained inscription commit txn hash", txnHash.String()) - // sendToTSSFromDeployerWithMemo makes sure index is 0 + // sendToAddrFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 hexTx, err := builder.GenerateRevealTxn(r.TSSAddress.String(), txnHash.String(), outpointIdx, amount) if err != nil { From 8582d877a82c7211d9ab8cf0da769a9736972557 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 10:16:56 +0800 Subject: [PATCH 14/41] update code --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 4 +--- e2e/runner/bitcoin.go | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index b88f760945..97a62f452e 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -36,11 +36,9 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { _, err = r.GenerateToAddressIfLocalBitcoin(6, r.BTCDeployerAddress) require.NoError(r, err) - gtx, err := r.BtcRPCClient.GetTransaction(txid) - require.NoError(r, err) - r.Logger.Info("rawtx confirmation: %d", gtx.BlockIndex) rawtx, err := r.BtcRPCClient.GetRawTransactionVerbose(txid) require.NoError(r, err) + r.Logger.Print("obtained reveal txn id %s", txid) depositorFee := zetabitcoin.DefaultDepositorFee events, err := btcobserver.FilterAndParseIncomingTx( diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index df0edc6703..23b014e696 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -318,7 +318,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - r.Logger.Print("obtained inscription commit txn hash", txnHash.String()) + r.Logger.Print("obtained inscription commit txn hash %s", txnHash.String()) // sendToAddrFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 @@ -326,7 +326,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - r.Logger.Print("obtained inscription reveal txn", hexTx) + r.Logger.Print("obtained inscription reveal txn %s", hexTx) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) @@ -339,7 +339,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { return nil, err } - r.Logger.Print("recovered inscription reveal txn", hexTx) + r.Logger.Print("recovered inscription reveal txn %s", hexTx) txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) require.NoError(r, err) From 1f706548d27de0d0d8aa339fa16586315818b611 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 10:27:34 +0800 Subject: [PATCH 15/41] add assertion --- .../test_extract_bitcoin_inscription_memo.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 97a62f452e..92dbbe0e97 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -51,12 +51,10 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { depositorFee, ) require.NoError(r, err) - r.Logger.Info("bitcoin inbound events:") - for _, event := range events { - r.Logger.Info(" TxHash: %s", event.TxHash) - r.Logger.Info(" From: %s", event.FromAddress) - r.Logger.Info(" To: %s", event.ToAddress) - r.Logger.Info(" Amount: %f", event.Value) - r.Logger.Info(" Memo: %x", event.MemoBytes) - } + + require.Equal(r, len(events), 1) + event := events[0] + r.Logger.Print("memo recovered %s", hex.EncodeToString(event.MemoBytes)) + + require.Equal(r, event.MemoBytes, memo) } From 508095a2b62a774b880cd8b7cce5fe616c2271c8 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 10:43:24 +0800 Subject: [PATCH 16/41] update tss address --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 92dbbe0e97..98a040a566 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -45,14 +45,14 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { r.BtcRPCClient, []btcjson.TxRawResult{*rawtx}, 0, - r.BTCTSSAddress.EncodeAddress(), + r.TSSAddress.String(), log.Logger, r.BitcoinParams, depositorFee, ) require.NoError(r, err) - require.Equal(r, len(events), 1) + require.Equal(r, 1, len(events)) event := events[0] r.Logger.Print("memo recovered %s", hex.EncodeToString(event.MemoBytes)) From 306856deeb0f60c25755490cff94beb79602a404 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 10:50:02 +0800 Subject: [PATCH 17/41] update code --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 98a040a566..f7863f0ca3 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -43,7 +43,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { depositorFee := zetabitcoin.DefaultDepositorFee events, err := btcobserver.FilterAndParseIncomingTx( r.BtcRPCClient, - []btcjson.TxRawResult{*rawtx}, + []btcjson.TxRawResult{*rawtx, *rawtx}, 0, r.TSSAddress.String(), log.Logger, From 475d8e0522c4819254aedd39367555a915d2d21a Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 10:52:25 +0800 Subject: [PATCH 18/41] update --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index f7863f0ca3..c470ee5e04 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -40,10 +40,11 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { require.NoError(r, err) r.Logger.Print("obtained reveal txn id %s", txid) + dummyCoinbaseTxn := rawtx depositorFee := zetabitcoin.DefaultDepositorFee events, err := btcobserver.FilterAndParseIncomingTx( r.BtcRPCClient, - []btcjson.TxRawResult{*rawtx, *rawtx}, + []btcjson.TxRawResult{*dummyCoinbaseTxn, *rawtx}, 0, r.TSSAddress.String(), log.Logger, From d14033b854b2ea7b6567f52f457e1374e8aa202a Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 11:02:18 +0800 Subject: [PATCH 19/41] more logs --- .../localnet/bitcoin-sidecar/js/src/client.ts | 25 +++---------------- e2e/runner/bitcoin.go | 2 +- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts index 4c76e6b2af..10b16b294f 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/client.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -13,14 +13,6 @@ initEccLib(ecc); const bip32 = BIP32Factory(ecc); const rng = randomBytes; - -export const DEFAULT_CONFIG = { - tss: { - mainnet: "bc1p24r8dky87hvauvpc3h798juvh6e3h0fw4sjfs2m4zuq99rd8p2jqt82578", - regtest: "bcrt1q7jaj5wvxvadwfz8ws6x8jdhgvrtrfn7n8sh4ks", - } -}; - /// The evm address type, a 20 bytes hex string export type Address = String; export type BtcAddress = String; @@ -159,7 +151,7 @@ class RevealTxnBuilder { }); this.psbt.addOutput({ - value: commitAmount - this.estimateFee(commitAmount, feeRate), + value: commitAmount - this.estimateFee(to, commitAmount, feeRate), address: to, }); @@ -173,12 +165,12 @@ class RevealTxnBuilder { return this.psbt.extractTransaction(true).toBuffer(); } - private estimateFee(amount: number, feeRate: number): number { + private estimateFee(to: string, amount: number, feeRate: number): number { const cloned = this.psbt.clone(); cloned.addOutput({ value: amount, - address: this.tssAddress(), + address: to, }); // should have a way to avoid signing but just providing mocked signautre @@ -188,15 +180,4 @@ class RevealTxnBuilder { const size = cloned.extractTransaction().virtualSize(); return size * feeRate; } - - private tssAddress(): string { - switch (this.network) { - case regtest: - return DEFAULT_CONFIG.tss.regtest; - case bitcoin: - return DEFAULT_CONFIG.tss.mainnet; - default: - throw Error("not supported"); - } - } } \ No newline at end of file diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 23b014e696..a9a420d0e5 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -326,7 +326,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - r.Logger.Print("obtained inscription reveal txn %s", hexTx) + r.Logger.Print("obtained inscription reveal txn %s sent to %s", hexTx, r.TSSAddress.String()) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) From c209bf951a2e44dd72d50fe9eda974aa968e8d7c Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 11:10:01 +0800 Subject: [PATCH 20/41] more fixes --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 2 +- e2e/runner/bitcoin.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index c470ee5e04..7a849e1ae5 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -46,7 +46,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { r.BtcRPCClient, []btcjson.TxRawResult{*dummyCoinbaseTxn, *rawtx}, 0, - r.TSSAddress.String(), + r.BTCTSSAddress.String(), log.Logger, r.BitcoinParams, depositorFee, diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index a9a420d0e5..0df21d6965 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -322,11 +322,11 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( // sendToAddrFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 - hexTx, err := builder.GenerateRevealTxn(r.TSSAddress.String(), txnHash.String(), outpointIdx, amount) + hexTx, err := builder.GenerateRevealTxn(r.BTCTSSAddress.String(), txnHash.String(), outpointIdx, amount) if err != nil { return nil, err } - r.Logger.Print("obtained inscription reveal txn %s sent to %s", hexTx, r.TSSAddress.String()) + r.Logger.Print("obtained inscription reveal txn %s sent to %s", hexTx, r.BTCTSSAddress.String()) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) From 3c47efb010d586fe8501cf8a7a57680043eb6b9d Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 11:38:21 +0800 Subject: [PATCH 21/41] reenabled tests --- cmd/zetae2e/local/local.go | 20 ++++----- .../localnet/bitcoin-sidecar/js/src/index.ts | 44 +------------------ .../test_extract_bitcoin_inscription_memo.go | 1 - e2e/runner/bitcoin.go | 1 - 4 files changed, 12 insertions(+), 54 deletions(-) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index e2e9fc90fe..69c606a6d2 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -254,12 +254,12 @@ func localE2ETest(cmd *cobra.Command, _ []string) { bitcoinTests := []string{ e2etests.TestExtractBitcoinInscriptionMemoName, - //e2etests.TestBitcoinDepositName, - //e2etests.TestBitcoinDepositRefundName, - //e2etests.TestBitcoinWithdrawSegWitName, - //e2etests.TestBitcoinWithdrawInvalidAddressName, - //e2etests.TestZetaWithdrawBTCRevertName, - //e2etests.TestCrosschainSwapName, + e2etests.TestBitcoinDepositName, + e2etests.TestBitcoinDepositRefundName, + e2etests.TestBitcoinWithdrawSegWitName, + e2etests.TestBitcoinWithdrawInvalidAddressName, + e2etests.TestZetaWithdrawBTCRevertName, + e2etests.TestCrosschainSwapName, } bitcoinAdvancedTests := []string{ e2etests.TestBitcoinWithdrawTaprootName, @@ -287,11 +287,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) { ethereumTests = append(ethereumTests, ethereumAdvancedTests...) } - //eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...)) - //eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...)) - //eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...)) + eg.Go(erc20TestRoutine(conf, deployerRunner, verbose, erc20Tests...)) + eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...)) + eg.Go(zevmMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...)) eg.Go(bitcoinTestRoutine(conf, deployerRunner, verbose, !skipBitcoinSetup, bitcoinTests...)) - //eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...)) + eg.Go(ethereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...)) } if testAdmin { diff --git a/contrib/localnet/bitcoin-sidecar/js/src/index.ts b/contrib/localnet/bitcoin-sidecar/js/src/index.ts index 160e4e742d..5164a6f148 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/index.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/index.ts @@ -1,7 +1,4 @@ -import * as readline from 'readline'; -import { ZetaBtcClient, BtcInput } from "./client"; -import { randomBytes } from 'crypto'; - +import { ZetaBtcClient } from "./client"; import express, { Request, Response } from 'express'; const app = express(); @@ -38,41 +35,4 @@ app.listen(PORT, () => { /** * curl --request POST --header "Content-Type: application/json" --data '{"memo":"72f080c854647755d0d9e6f6821f6931f855b9acffd53d87433395672756d58822fd143360762109ab898626556b1c3b8d3096d2361f1297df4a41c1b429471a9aa2fc9be5f27c13b3863d6ac269e4b587d8389f8fd9649859935b0d48dea88cdb40f20c"}' http://localhost:3000/commit * curl --request POST --header "Content-Type: application/json" --data '{"txn": "7a57f987a3cb605896a5909d9ef2bf7afbf0c78f21e4118b85d00d9e4cce0c2c", "idx": 0, "amount": 1000, "feeRate": 10}' http://localhost:3000/reveal - */ -// async function main() { -// const client = ZetaBtcClient.regtest(); - -// const data = randomBytes(100); -// console.log("random", data.toString("hex")); - -// const d = client.call("", data); -// console.log("Commit address:", d); - -// // use wallet to transfer amount to the target address - -// // obtain the txn id, index, and amount -// const [commitInput, commitAmt] = await obtainTxn(); -// const txn = client.buildRevealTxn(commitInput, commitAmt, 10); -// // txn ready to be broadcasted -// console.log(txn.toString("hex")); - -// } - -// async function obtainTxn(): Promise<[BtcInput, number]> { -// const rl = readline.createInterface({ -// input: process.stdin, -// output: process.stdout -// }); - -// return new Promise((resolve) => { -// rl.question('\nInput txn hash, txn index and amount sent: ', (answer) => { -// rl.close(); - -// const parts = answer.split(" "); -// resolve([{ txn: parts[0], idx: Number(parts[1])}, Number(parts[2])]); -// }); -// }); -// } - -// main() -// .then(() => console.log("done")); \ No newline at end of file + */ \ No newline at end of file diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 7a849e1ae5..8ef669ce41 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -55,7 +55,6 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { require.Equal(r, 1, len(events)) event := events[0] - r.Logger.Print("memo recovered %s", hex.EncodeToString(event.MemoBytes)) require.Equal(r, event.MemoBytes, memo) } diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 0df21d6965..eeb500e0f9 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -326,7 +326,6 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err != nil { return nil, err } - r.Logger.Print("obtained inscription reveal txn %s sent to %s", hexTx, r.BTCTSSAddress.String()) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) From 4e7b69533b4209844d2f13f141cddf1894122fea Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 16 Aug 2024 12:43:13 +0800 Subject: [PATCH 22/41] remove unused code --- contrib/localnet/bitcoin-sidecar/js/src/reveal.ts | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 contrib/localnet/bitcoin-sidecar/js/src/reveal.ts diff --git a/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts b/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts deleted file mode 100644 index 7a4bc45394..0000000000 --- a/contrib/localnet/bitcoin-sidecar/js/src/reveal.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ZetaBtcClient } from "./client"; - -function main() { - const client = ZetaBtcClient.regtest(); - - const data = Buffer.alloc(600); - - const d = client.call("", data); - - console.log(d); -} - -main(); \ No newline at end of file From b56767c0519514d4914355784cc88cb645c96c14 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:31:18 +0800 Subject: [PATCH 23/41] Update cmd/zetae2e/local/bitcoin.go Co-authored-by: Lucas Bertrand --- cmd/zetae2e/local/bitcoin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 6a8532c69b..a292c5c968 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -61,7 +61,6 @@ func bitcoinTestRoutine( return fmt.Errorf("bitcoin tests failed: %v", err) } - bitcoinRunner.Logger.Print("Running tests:", testNames) if err := bitcoinRunner.RunE2ETests(testsToRun); err != nil { return fmt.Errorf("bitcoin tests failed: %v", err) From 2da0d34104f07c421eac658e3291feb83ef29349 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:31:39 +0800 Subject: [PATCH 24/41] Update contrib/localnet/bitcoin-sidecar/js/src/client.ts Co-authored-by: Lucas Bertrand --- contrib/localnet/bitcoin-sidecar/js/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts index 10b16b294f..ed7b3a9ab1 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/client.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -17,7 +17,7 @@ const rng = randomBytes; export type Address = String; export type BtcAddress = String; -/// The BTC transactioin hash returned +/// The BTC transaction hash returned export type BtcTxnHash = String; export interface BtcInput { txn: BtcTxnHash, From 5f3ade15b6e75519d3a566d0843131d630458e1e Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:33:01 +0800 Subject: [PATCH 25/41] Update contrib/localnet/bitcoin-sidecar/js/src/client.ts Co-authored-by: Lucas Bertrand --- contrib/localnet/bitcoin-sidecar/js/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts index ed7b3a9ab1..7e20fc8da5 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/client.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -25,7 +25,7 @@ export interface BtcInput { } /** - * The example client for interracting with Zetachain in BTC. There are currently two ways + * The example client for interacting with ZetaChain in BTC. There are currently two ways * of calling a smart contract on Zetachain from BTC: * * - Using OP_RETURN From 77f71c2c1df2bc64094a9c936c8a174bca6820a2 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:33:12 +0800 Subject: [PATCH 26/41] Update contrib/localnet/bitcoin-sidecar/js/src/client.ts Co-authored-by: Lucas Bertrand --- contrib/localnet/bitcoin-sidecar/js/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/localnet/bitcoin-sidecar/js/src/client.ts b/contrib/localnet/bitcoin-sidecar/js/src/client.ts index 7e20fc8da5..eccc747672 100644 --- a/contrib/localnet/bitcoin-sidecar/js/src/client.ts +++ b/contrib/localnet/bitcoin-sidecar/js/src/client.ts @@ -26,7 +26,7 @@ export interface BtcInput { /** * The example client for interacting with ZetaChain in BTC. There are currently two ways - * of calling a smart contract on Zetachain from BTC: + * of calling a smart contract on ZetaChain from BTC: * * - Using OP_RETURN * - Using Witness From f2bffb209596fb774b671ee867272d36f6f60dd7 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:33:19 +0800 Subject: [PATCH 27/41] Update e2e/runner/bitcoin.go Co-authored-by: Lucas Bertrand --- e2e/runner/bitcoin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index eeb500e0f9..094be80879 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -338,7 +338,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { return nil, err } - r.Logger.Print("recovered inscription reveal txn %s", hexTx) + r.Logger.Info("recovered inscription reveal txn %s", hexTx) txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) require.NoError(r, err) From efcebdc3f51eae2d88689c31584655abc3fe4696 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:33:30 +0800 Subject: [PATCH 28/41] Update e2e/e2etests/test_extract_bitcoin_inscription_memo.go Co-authored-by: Lucas Bertrand --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 8ef669ce41..61ffe96acd 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -12,7 +12,6 @@ import ( ) func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { - r.Logger.Print("Testing extract memo from btc inscription") r.SetBtcAddress(r.Name, false) From 2ed136c5639c0ff582a00c0c27fb2e7d1dc1c9b1 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:33:41 +0800 Subject: [PATCH 29/41] Update e2e/e2etests/test_extract_bitcoin_inscription_memo.go Co-authored-by: Lucas Bertrand --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 61ffe96acd..cf5bdc5cad 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -18,7 +18,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { // obtain some initial fund stop := r.MineBlocksIfLocalBitcoin() defer stop() - r.Logger.Print("Mined blocks") + r.Logger.Info("Mined blocks") // list deployer utxos utxos, err := r.ListDeployerUTXOs() From bc02de7a917db0517f26dbf651777e864e60c128 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:34:08 +0800 Subject: [PATCH 30/41] Update e2e/e2etests/test_extract_bitcoin_inscription_memo.go Co-authored-by: Lucas Bertrand --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index cf5bdc5cad..dc2eed31fe 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -37,7 +37,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { rawtx, err := r.BtcRPCClient.GetRawTransactionVerbose(txid) require.NoError(r, err) - r.Logger.Print("obtained reveal txn id %s", txid) + r.Logger.Info("obtained reveal txn id %s", txid) dummyCoinbaseTxn := rawtx depositorFee := zetabitcoin.DefaultDepositorFee From 7bf9b076708dae3eeee0daced87fdd9381695fd4 Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:34:33 +0800 Subject: [PATCH 31/41] Update e2e/runner/bitcoin.go Co-authored-by: Lucas Bertrand --- e2e/runner/bitcoin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 094be80879..be25b5b979 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -301,6 +301,8 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( inputUTXOs []btcjson.ListUnspentResult, memo []byte, ) (*chainhash.Hash, error) { + // TODO: replace builder with Go function to enable instructions + // https://github.com/zeta-chain/node/issues/2759 builder := InscriptionBuilder{sidecarUrl: "http://bitcoin-node-sidecar:8000", client: http.Client{}} address, err := builder.GenerateCommitAddress(memo) From 9e498bccd34d9e1b40a88e863a64374b2971f3e2 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Aug 2024 20:18:43 +0800 Subject: [PATCH 32/41] update test order --- cmd/zetae2e/local/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index b58b0cbceb..017f4e9448 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -269,7 +269,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { } bitcoinTests := []string{ - e2etests.TestExtractBitcoinInscriptionMemoName, e2etests.TestBitcoinDepositName, e2etests.TestBitcoinDepositRefundName, e2etests.TestBitcoinWithdrawSegWitName, @@ -284,6 +283,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestBitcoinWithdrawP2SHName, e2etests.TestBitcoinWithdrawP2WSHName, e2etests.TestBitcoinWithdrawRestrictedName, + e2etests.TestExtractBitcoinInscriptionMemoName, } ethereumTests := []string{ e2etests.TestEtherWithdrawName, From 152b0d78e67fd6e5935b9b0a1f99b1e15d2143bf Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:26:33 +0800 Subject: [PATCH 33/41] Update e2e/e2etests/test_extract_bitcoin_inscription_memo.go Co-authored-by: Lucas Bertrand --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index dc2eed31fe..c68a9d72c4 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -25,9 +25,10 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { require.NoError(r, err) amount := parseFloat(r, args[0]) - memo, _ := hex.DecodeString( + memo, err := hex.DecodeString( "72f080c854647755d0d9e6f6821f6931f855b9acffd53d87433395672756d58822fd143360762109ab898626556b1c3b8d3096d2361f1297df4a41c1b429471a9aa2fc9be5f27c13b3863d6ac269e4b587d8389f8fd9649859935b0d48dea88cdb40f20c", ) + require.NoError(r, err) txid, err := r.InscribeToTSSFromDeployerWithMemo(amount, utxos, memo) require.NoError(r, err) From b341832369fe9601a10341f5dc1a4975dcb7e7e1 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Aug 2024 20:40:08 +0800 Subject: [PATCH 34/41] return nil neither both op_ret nor inscription found --- e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 1 + e2e/runner/bitcoin.go | 2 +- e2e/runner/inscription.go | 6 +++--- zetaclient/chains/bitcoin/observer/witness.go | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index c68a9d72c4..9bddb0ea3f 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -25,6 +25,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { require.NoError(r, err) amount := parseFloat(r, args[0]) + // this is just some random test memo for inscription memo, err := hex.DecodeString( "72f080c854647755d0d9e6f6821f6931f855b9acffd53d87433395672756d58822fd143360762109ab898626556b1c3b8d3096d2361f1297df4a41c1b429471a9aa2fc9be5f27c13b3863d6ac269e4b587d8389f8fd9649859935b0d48dea88cdb40f20c", ) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index be25b5b979..2cae8e076f 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -303,7 +303,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( ) (*chainhash.Hash, error) { // TODO: replace builder with Go function to enable instructions // https://github.com/zeta-chain/node/issues/2759 - builder := InscriptionBuilder{sidecarUrl: "http://bitcoin-node-sidecar:8000", client: http.Client{}} + builder := InscriptionBuilder{sidecarURL: "http://bitcoin-node-sidecar:8000", client: http.Client{}} address, err := builder.GenerateCommitAddress(memo) if err != nil { diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 656e4acc58..944c40d4ac 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -28,7 +28,7 @@ type revealRequest struct { // InscriptionBuilder is a util struct that help create inscription commit and reveal transactions type InscriptionBuilder struct { - sidecarUrl string + sidecarURL string client http.Client } @@ -44,7 +44,7 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) return "", err } - postUrl := r.sidecarUrl + "/commit" + postUrl := r.sidecarURL + "/commit" req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) if err != nil { return "", errors.Wrap(err, "cannot create commit request") @@ -85,7 +85,7 @@ func (r *InscriptionBuilder) GenerateRevealTxn(to string, txnHash string, idx in return "", err } - postUrl := r.sidecarUrl + "/reveal" + postUrl := r.sidecarURL + "/reveal" req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) if err != nil { return "", errors.Wrap(err, "cannot create reveal request") diff --git a/zetaclient/chains/bitcoin/observer/witness.go b/zetaclient/chains/bitcoin/observer/witness.go index 0af55c62a9..aef4da54e1 100644 --- a/zetaclient/chains/bitcoin/observer/witness.go +++ b/zetaclient/chains/bitcoin/observer/witness.go @@ -58,7 +58,7 @@ func GetBtcEventWithWitness( memo = candidate logger.Debug().Msgf("GetBtcEventWithWitness: found inscription memo %s in tx %s", hex.EncodeToString(memo), tx.Txid) } else { - return nil, errors.Errorf("error getting memo for inbound: %s", tx.Txid) + return nil, nil } // event found, get sender address From 41339140c2071d6a4e330d1f9fa3d58df9022181 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Aug 2024 20:53:53 +0800 Subject: [PATCH 35/41] require not err --- .../test_extract_bitcoin_inscription_memo.go | 3 +- e2e/runner/bitcoin.go | 29 ++++++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index 9bddb0ea3f..e4939acdcd 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -31,8 +31,7 @@ func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { ) require.NoError(r, err) - txid, err := r.InscribeToTSSFromDeployerWithMemo(amount, utxos, memo) - require.NoError(r, err) + txid := r.InscribeToTSSFromDeployerWithMemo(amount, utxos, memo) _, err = r.GenerateToAddressIfLocalBitcoin(6, r.BTCDeployerAddress) require.NoError(r, err) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 2cae8e076f..aec169e808 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -300,53 +300,42 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( amount float64, inputUTXOs []btcjson.ListUnspentResult, memo []byte, -) (*chainhash.Hash, error) { +) *chainhash.Hash { // TODO: replace builder with Go function to enable instructions // https://github.com/zeta-chain/node/issues/2759 builder := InscriptionBuilder{sidecarURL: "http://bitcoin-node-sidecar:8000", client: http.Client{}} address, err := builder.GenerateCommitAddress(memo) - if err != nil { - return nil, err - } + require.NoError(r, err) r.Logger.Print("received inscription commit address %s", address) receiver, err := chains.DecodeBtcAddress(address, r.GetBitcoinChainID()) - if err != nil { - return nil, err - } + require.NoError(r, err) txnHash, err := r.sendToAddrFromDeployerWithMemo(amount, receiver, inputUTXOs, []byte(constant.DonationMessage)) - if err != nil { - return nil, err - } + require.NoError(r, err) r.Logger.Print("obtained inscription commit txn hash %s", txnHash.String()) // sendToAddrFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 hexTx, err := builder.GenerateRevealTxn(r.BTCTSSAddress.String(), txnHash.String(), outpointIdx, amount) - if err != nil { - return nil, err - } + require.NoError(r, err) // Decode the hex string into raw bytes rawTxBytes, err := hex.DecodeString(hexTx) - if err != nil { - return nil, err - } + require.NoError(r, err) // Deserialize the raw bytes into a wire.MsgTx structure msgTx := wire.NewMsgTx(wire.TxVersion) - if err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)); err != nil { - return nil, err - } + err = msgTx.Deserialize(bytes.NewReader(rawTxBytes)) + require.NoError(r, err) r.Logger.Info("recovered inscription reveal txn %s", hexTx) txid, err := r.BtcRPCClient.SendRawTransaction(msgTx, true) require.NoError(r, err) r.Logger.Info("txid: %+v", txid) - return txid, nil + return txid } // GetBitcoinChainID gets the bitcoin chain ID from the network params From 7e394eb05cc6f93a44abda4cb8b08aade89e230f Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:55:53 +0800 Subject: [PATCH 36/41] Update e2e/runner/bitcoin.go Co-authored-by: Lucas Bertrand --- e2e/runner/bitcoin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index aec169e808..acf701a99f 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -307,7 +307,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( address, err := builder.GenerateCommitAddress(memo) require.NoError(r, err) - r.Logger.Print("received inscription commit address %s", address) + r.Logger.Info("received inscription commit address %s", address) receiver, err := chains.DecodeBtcAddress(address, r.GetBitcoinChainID()) require.NoError(r, err) From 4fd2d197a23aceefe1ccdaadd6789ca71e70334b Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:02:33 +0800 Subject: [PATCH 37/41] Update e2e/runner/bitcoin.go Co-authored-by: Lucas Bertrand --- e2e/runner/bitcoin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index acf701a99f..99a9ed440b 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -314,7 +314,7 @@ func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( txnHash, err := r.sendToAddrFromDeployerWithMemo(amount, receiver, inputUTXOs, []byte(constant.DonationMessage)) require.NoError(r, err) - r.Logger.Print("obtained inscription commit txn hash %s", txnHash.String()) + r.Logger.Info("obtained inscription commit txn hash %s", txnHash.String()) // sendToAddrFromDeployerWithMemo makes sure index is 0 outpointIdx := 0 From b49c074fa7e73c8bbb6482d1b9bd5e94a34a459d Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Aug 2024 21:04:08 +0800 Subject: [PATCH 38/41] more comments --- e2e/runner/bitcoin.go | 1 + e2e/runner/inscription.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 99a9ed440b..b7c601a21e 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -296,6 +296,7 @@ func (r *E2ERunner) sendToAddrFromDeployerWithMemo( return txid, nil } +// InscribeToTSSFromDeployerWithMemo creates an inscription that is sent to the tss address with the corresponding memo func (r *E2ERunner) InscribeToTSSFromDeployerWithMemo( amount float64, inputUTXOs []btcjson.ListUnspentResult, diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 944c40d4ac..109fb03f0a 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -32,6 +32,7 @@ type InscriptionBuilder struct { client http.Client } +// GenerateCommitAddress generates a commit p2tr address that one can send funds to this address func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) { // Create the payload postData := map[string]string{ @@ -70,6 +71,7 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) return response.Address, nil } +// GenerateRevealTxn creates the corresponding reveal txn to the commit txn. func (r *InscriptionBuilder) GenerateRevealTxn(to string, txnHash string, idx int, amount float64) (string, error) { postData := revealRequest{ Txn: txnHash, From 7b0ca65254bd14c391db925b36a10cfbea70822d Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 21 Aug 2024 23:16:28 +0800 Subject: [PATCH 39/41] fix lint --- cmd/zetae2e/local/bitcoin.go | 1 - e2e/e2etests/test_extract_bitcoin_inscription_memo.go | 6 +++--- e2e/runner/inscription.go | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index a292c5c968..184277d0cc 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -61,7 +61,6 @@ func bitcoinTestRoutine( return fmt.Errorf("bitcoin tests failed: %v", err) } - if err := bitcoinRunner.RunE2ETests(testsToRun); err != nil { return fmt.Errorf("bitcoin tests failed: %v", err) } diff --git a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go index e4939acdcd..2713326ba7 100644 --- a/e2e/e2etests/test_extract_bitcoin_inscription_memo.go +++ b/e2e/e2etests/test_extract_bitcoin_inscription_memo.go @@ -2,17 +2,17 @@ package e2etests import ( "encoding/hex" + "github.com/btcsuite/btcd/btcjson" "github.com/rs/zerolog/log" "github.com/stretchr/testify/require" - zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin" - btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer" "github.com/zeta-chain/zetacore/e2e/runner" + zetabitcoin "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin" + btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer" ) func TestExtractBitcoinInscriptionMemo(r *runner.E2ERunner, args []string) { - r.SetBtcAddress(r.Name, false) // obtain some initial fund diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 109fb03f0a..8abc07c331 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -5,9 +5,10 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/pkg/errors" "io" "net/http" + + "github.com/pkg/errors" ) type commitResponse struct { From 9e38b187ccd320b3cb10cdc0e772693683055c5b Mon Sep 17 00:00:00 2001 From: dev-bitSmiley <153714963+bitSmiley@users.noreply.github.com> Date: Wed, 21 Aug 2024 23:19:48 +0800 Subject: [PATCH 40/41] Update changelog.md --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index d6791e1659..b44b296748 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ * [2681](https://github.com/zeta-chain/node/pull/2681) - implement `MsgUpdateERC20CustodyPauseStatus` to pause or unpause ERC20 Custody contract (to be used for the migration process for smart contract V2) * [2644](https://github.com/zeta-chain/node/pull/2644) - add created_timestamp to cctx status * [2673](https://github.com/zeta-chain/node/pull/2673) - add relayer key importer, encryption and decryption +* [2727](https://github.com/zeta-chain/node/pull/2727) - enable op_return and inscription in memo detection ### Refactor From 34789672a80da069d7c087a9f7b81398ef5d147e Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 23 Aug 2024 12:19:52 +0800 Subject: [PATCH 41/41] fix lint --- e2e/runner/inscription.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/runner/inscription.go b/e2e/runner/inscription.go index 8abc07c331..6f90068905 100644 --- a/e2e/runner/inscription.go +++ b/e2e/runner/inscription.go @@ -46,8 +46,8 @@ func (r *InscriptionBuilder) GenerateCommitAddress(memo []byte) (string, error) return "", err } - postUrl := r.sidecarURL + "/commit" - req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) + postURL := r.sidecarURL + "/commit" + req, err := http.NewRequest("POST", postURL, bytes.NewBuffer(jsonData)) if err != nil { return "", errors.Wrap(err, "cannot create commit request") } @@ -88,8 +88,8 @@ func (r *InscriptionBuilder) GenerateRevealTxn(to string, txnHash string, idx in return "", err } - postUrl := r.sidecarURL + "/reveal" - req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData)) + postURL := r.sidecarURL + "/reveal" + req, err := http.NewRequest("POST", postURL, bytes.NewBuffer(jsonData)) if err != nil { return "", errors.Wrap(err, "cannot create reveal request") }