"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
require("source-map-support/register");
require("jest");
const Struct_1 = require("@wireio/sdk-core/chain/Struct");
const Name_1 = require("@wireio/sdk-core/chain/Name");
const Integer_1 = require("@wireio/sdk-core/chain/Integer");
let Transfer = class Transfer extends Struct_1.Struct {
};
__decorate([
    Struct_1.Struct.field("name"),
    __metadata("design:type", Name_1.Name)
], Transfer.prototype, "from", void 0);
__decorate([
    Struct_1.Struct.field("name"),
    __metadata("design:type", Name_1.Name)
], Transfer.prototype, "to", void 0);
__decorate([
    Struct_1.Struct.field("uint64"),
    __metadata("design:type", Integer_1.UInt64)
], Transfer.prototype, "amount", void 0);
Transfer = __decorate([
    Struct_1.Struct.type("transfer")
], Transfer);
describe("Struct", () => {
    describe("from", () => {
        it("creates an instance from a plain object", () => {
            const transfer = Transfer.from({
                from: "alice",
                to: "bob",
                amount: 100
            });
            expect(transfer).toBeInstanceOf(Transfer);
        });
        it("has correctly typed fields", () => {
            const transfer = Transfer.from({
                from: "alice",
                to: "bob",
                amount: 100
            });
            expect(transfer.from).toBeInstanceOf(Name_1.Name);
            expect(transfer.to).toBeInstanceOf(Name_1.Name);
            expect(String(transfer.from)).toBe("alice");
            expect(String(transfer.to)).toBe("bob");
        });
    });
    describe("equals", () => {
        it("returns true for equal structs", () => {
            const a = Transfer.from({ from: "alice", to: "bob", amount: 100 });
            const b = Transfer.from({ from: "alice", to: "bob", amount: 100 });
            expect(a.equals(b)).toBe(true);
        });
        it("returns false for different structs", () => {
            const a = Transfer.from({ from: "alice", to: "bob", amount: 100 });
            const b = Transfer.from({ from: "alice", to: "bob", amount: 200 });
            expect(a.equals(b)).toBe(false);
        });
    });
    describe("decorators", () => {
        it("registers ABI name via Struct.type", () => {
            expect(Transfer.abiName).toBe("transfer");
        });
        it("registers ABI fields via Struct.field", () => {
            const fields = Transfer.structFields;
            expect(fields).toBeDefined();
            expect(fields.length).toBe(3);
            expect(fields[0].name).toBe("from");
            expect(fields[1].name).toBe("to");
            expect(fields[2].name).toBe("amount");
        });
    });
});
//# sourceMappingURL=Struct.test.js.map