"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const attestations_1 = require("./attestations");
const ethers_1 = require("ethers");
const ethers_2 = require("ethers");
const bs58 = __importStar(require("bs58"));
describe('Attestations', () => {
    const mnemonic = 'coyote tattoo slush ball cluster culture bleak news when action cover effort';
    test('Attestations are correct', () => __awaiter(void 0, void 0, void 0, function* () {
        const receipt = {
            requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
            responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
            subgraphDeploymentID: ethers_2.utils.hexlify(bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2)),
        };
        const signer = ethers_1.Wallet.fromMnemonic(mnemonic);
        const attestation = yield attestations_1.createAttestation(signer.privateKey, 1, '0x0000000000000000000000000000000000000000', receipt);
        expect(attestation).toStrictEqual({
            requestCID: receipt.requestCID,
            responseCID: receipt.responseCID,
            subgraphDeploymentID: receipt.subgraphDeploymentID,
            v: 27,
            r: '0x00bd2f5c3dd7a81dc36a6bf109e4deba55220c0badd5d6e2e1b3aefb48d647e4',
            s: '0x34ca501c609bef062785671d594be732ef7af1ddbaffd8f3257a2ad606479769',
        });
    }));
    test('encode and decode attestation', () => __awaiter(void 0, void 0, void 0, function* () {
        const receipt = {
            requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
            responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
            subgraphDeploymentID: ethers_2.utils.hexlify(bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2)),
        };
        const attestation = {
            requestCID: receipt.requestCID,
            responseCID: receipt.responseCID,
            subgraphDeploymentID: receipt.subgraphDeploymentID,
            v: 27,
            r: '0x00bd2f5c3dd7a81dc36a6bf109e4deba55220c0badd5d6e2e1b3aefb48d647e4',
            s: '0x34ca501c609bef062785671d594be732ef7af1ddbaffd8f3257a2ad606479769',
        };
        const attestationBytes = attestations_1.encodeAttestation(attestation);
        const decodedAttestation = attestations_1.decodeAttestation(attestationBytes);
        expect(decodedAttestation).toStrictEqual(attestation);
    }));
    test('recover attestation signer', () => __awaiter(void 0, void 0, void 0, function* () {
        const receipt = {
            requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
            responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
            subgraphDeploymentID: ethers_2.utils.hexlify(bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2)),
        };
        const signer = ethers_1.Wallet.fromMnemonic(mnemonic);
        const chainID = 1;
        const contractAddress = '0x0000000000000000000000000000000000000000';
        const attestation = yield attestations_1.createAttestation(signer.privateKey, chainID, contractAddress, receipt);
        const recoveredAddress = attestations_1.recoverAttestation(chainID, contractAddress, attestation);
        expect(recoveredAddress).toStrictEqual(yield signer.getAddress());
    }));
});
//# sourceMappingURL=attestations.test.js.map