Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Polygon zkEVM bridge example #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (c *Client) pollForBlocks() {
prevBlock = block

rootTS := metrics.NewRegistry().RootTagSet()
if c.vu != nil || c.vu.State() != nil || rootTS != nil {
if c.vu != nil && c.vu.State() != nil && rootTS != nil {
if _, loaded := blocks.LoadOrStore(c.opts.URL+strconv.FormatUint(blockNumber, 10), true); loaded {
// We already have a block number for this client, so we can skip this
continue
Expand Down
42 changes: 42 additions & 0 deletions examples/bridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import eth from 'k6/x/ethereum';

const contract = JSON.parse(open("./contracts/PolygonZkEVMBridgeV2.json"));

// You can use an existing premined account
const root_address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";

const l1_client = new eth.Client({
privateKey: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
url: "http://localhost:8545"
});

const l2_client = new eth.Client({
privateKey: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
url: "http://localhost:8123"
});

const bridge = "0x80a540502706aa690476D5534e26939894559c05";

// VU client
export default function () {
const con = l1_client.newContract(bridge, JSON.stringify(contract.abi));

let nonce = client.getNonce(root_address);
let txhash = con.txn(
"bridgeAsset", { gas_limit: 100000, nonce: nonce },
0x0,
root_address,
0.0001 * 1e18,
"0x0000000000000000000000000000000000000000",
false,
"",
);

console.log(`txn hash => ${txhash}`);

client.waitForTransactionReceipt(txhash).then((receipt) => {
console.log("tx block hash => " + receipt.block_hash);
});

console.log(JSON.stringify(client.getBalance(root_address)));
}
17 changes: 17 additions & 0 deletions examples/comet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import http from "k6/http";
import exec from 'k6/execution';

export const options = {
iterations: 600,
vus: 600,
};

let tally = 0;

export default function () {
const response = http.get('http://localhost:26657/broadcast_tx_commit?tx="cometbft=rocks' + exec.vu.idInInstance + '-' + tally +'"');
tally++;

const body = JSON.parse(response.body);
console.log(body);
}
Loading