Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add tests of error ABI to contract-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Apr 21, 2021
1 parent 13f9e7b commit 89d1ff5
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions packages/contract-schema/test/abi-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,128 @@ describe("ABI Schema", function() {
});
});

describe("error definition", function() {
it("validates with all fields valid", function() {
var abi = [
{
type: "error",
name: "InsufficientBalance",
inputs: [
{
name: "needed",
type: "uint256",
},
{
name: "actual",
type: "uint256",
}
]
}
];

assert(validate(abi));
});

it("cannot omit type", function() {
var abi = [
{
name: "InsufficientBalance",
inputs: [
{
name: "needed",
type: "uint256",
},
{
name: "actual",
type: "uint256",
}
]
}
];

assert(!validate(abi));
});

it("cannot omit name", function() {
var abi = [
{
type: "error",
inputs: [
{
name: "needed",
type: "uint256",
},
{
name: "actual",
type: "uint256",
}
]
}
];

assert(!validate(abi));
});

it("cannot omit inputs", function() {
var abi = [
{
type: "error",
name: "InsufficientBalance"
}
];

assert(!validate(abi));
});
});

describe("normal function definition", function() {
it("can omit type, outputs, constant, and payable", function() {
var abi = [
{
name: "press",
inputs: [
{
name: "button",
type: "uint256"
}
],
stateMutability: "nonpayable"
}
];

assert(validate(abi));
assert.equal(abi[0].type, "function");
assert.equal(abi[0].stateMutability, "nonpayable");
assert.deepEqual(abi[0].outputs, []);
});

it("cannot omit name", function() {
var abi = [
{
type: "function",
outputs: [],
inputs: [],
stateMutability: "nonpayable"
}
];

assert(!validate(abi));
});

it("cannot omit inputs", function() {
var abi = [
{
name: "pressButton",
type: "function",
outputs: [],
stateMutability: "nonpayable"
}
];

assert(!validate(abi));
});
});

describe("constructor function definition", function() {
it("can omit constant, and payable", function() {
var abi = [
Expand Down

0 comments on commit 89d1ff5

Please sign in to comment.