Skip to content

Instantly share code, notes, and snippets.

View cargopete's full-sized avatar
:shipit:

Petko Pavlovski cargopete

:shipit:
  • Fathom.io
  • Europe
View GitHub Profile
[dotenv@17.2.0] injecting env (7) from .env (tip: 🔐 encrypt with dotenvx: https://dotenvx.com)
// Sources flattened with hardhat v2.25.0 https://hardhat.org
// SPDX-License-Identifier: MIT
// File @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
#!/bin/bash
#
# Subgraph Size Checker - Final Version
#
# Finds size of a Graph Protocol subgraph by QM hash
#
# Usage:
# ./graph-size.sh QmQcQdQZxbvSR1KpMcJQfppSuEXzh1MzsSad3Gyyc4M5Jo
#
@cargopete
cargopete / main.rs
Created April 8, 2025 07:18
Solution
use rand::Rng;
use rand::seq::SliceRandom;
use std::collections::{HashSet, BTreeSet};
use std::time::Instant;
use rand::distributions::{Distribution, Uniform};
/// optimized for different scenarios including huge (GB) data ranges
fn generate_unique_random_numbers(begin: i64, end: i64, count: usize) -> Vec<i64> {
let range_size = (end - begin + 1) as usize;
if count > range_size {
import { test } from "matchstick-as/assembly/index";
import { log } from "matchstick-as/assembly/log";
export function runTests(): void {
test("Success", () => {
log.success("Success!");
});
test("Error", () => {
log.error("Error :( ");
});
import { assert } from "matchstick-as/assembly/index";
import { ethereum } from "@graphprotocol/graph-ts";
assert.equals(ethereum.Value.fromString("hello"), ethereum.Value.fromString("hello"));
import { newMockEvent } from "matchstick-as/assembly/index";
import { ethereum, Address } from "@graphprotocol/graph-ts";
import { NewCustomEntity } from "../generated/MyDataSource/Example";
let newEntityEvent = newMockEvent(new NewCustomEntity()) as NewCustomEntity;
// Read
let logType = newEntityEvent.logType;
// Write
import { addMetadata } from "matchstick-as/assembly/index";
import { ethereum } from "@graphprotocol/graph-ts";
import { NewCustomEntity } from "../generated/MyDataSource/Example";
let base: ethereum.Event = new NewCustomEntity();
let newEntityEvent: NewCustomEntity = addMetadata(base);
import { assert, createMockedFunction } from "matchstick-as/assembly/index";
import { Contract } from "../../generated/MyDataSource/Example";
import { Address, ethereum } from "@graphprotocol/graph-ts";
let contractAddress = Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7");
let arg = ethereum.Value.fromString("example string arg");
createMockedFunction(contractAddress, "functionName", "functionName(string):(string)")
.withArgs([arg])
.reverts();
import { assert, createMockedFunction } from "matchstick-as/assembly/index";
import { Contract } from "../../generated/MyDataSource/Example";
import { Address, ethereum } from "@graphprotocol/graph-ts";
let contractAddress = Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7");
let arg = ethereum.Value.fromString("example string arg");
createMockedFunction(contractAddress, "functionName", "functionName(string):(string)")
.withArgs([arg])
.returns([ethereum.Value.fromString("result")]);
import { test, assert } from "matchstick-as/assembly/index";
import { CustomEntity } from '../../generated/schema';
import { Value } from "@graphprotocol/graph-ts";
export function runTests(): void {
test("Next test", () => {
let customEntity = new CustomEntity("434");
customEntity.set("name", Value.fromString("Frederick"));
customEntity.save();