Skip to content

Commit

Permalink
make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jul 4, 2024
1 parent 48816cd commit 473205a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
49 changes: 21 additions & 28 deletions test/axelar-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,71 +112,70 @@ describe('Axelar Gateway', () => {
});

describe('Signer Rotation', () => {

it('Should rotate signers', async () => {
await sleep(2000);
const proofSigners = signers;
const proofKeys = operatorKeys;
calculateNextSigners();

const encodedSigners = axelarStructs.WeightedSigners.serialize(signers).toBytes();

const hashed = hashMessage(encodedSigners);

const message = axelarStructs.MessageToSign.serialize({
domain_separator: domainSeparator,
signers_hash: keccak256(axelarStructs.WeightedSigners.serialize(proofSigners).toBytes()),
data_hash: hashed,
}).toBytes();

const signatures = sign(proofKeys, message);
const encodedProof = axelarStructs.Proof.serialize({
signers: proofSigners,
signatures,
}).toBytes();

const builder = new TxBuilder(client);

await builder.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [gateway, '0x6', encodedSigners, encodedProof],
});

await builder.signAndExecute(keypair);
});

it('Should not rotate to empty signers', async () => {
await sleep(2000);
const proofSigners = signers;
const proofKeys = operatorKeys;

const encodedSigners = axelarStructs.WeightedSigners.serialize({
signers: [],
threshold: 2,
nonce: hexlify([nonce + 1]),
}).toBytes();

const hashed = hashMessage(encodedSigners);

const message = axelarStructs.MessageToSign.serialize({
domain_separator: domainSeparator,
signers_hash: keccak256(axelarStructs.WeightedSigners.serialize(proofSigners).toBytes()),
data_hash: hashed,
}).toBytes();

const signatures = sign(proofKeys, message);
const encodedProof = axelarStructs.Proof.serialize({
signers: proofSigners,
signatures,
}).toBytes();

const builder = new TxBuilder(client);

await builder.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [gateway, '0x6', encodedSigners, encodedProof],
});

await expectRevert(builder, keypair, {
packageId,
module: 'weighted_signers',
Expand All @@ -188,7 +187,7 @@ describe('Axelar Gateway', () => {

describe('Contract Call', () => {
let channel;
before(async() => {
before(async () => {
const builder = new TxBuilder(client);

channel = await builder.moveCall({
Expand All @@ -202,7 +201,7 @@ describe('Axelar Gateway', () => {
const response = await builder.signAndExecute(keypair);

channel = response.objectChanges.find((change) => change.objectType === `${packageId}::channel::Channel`).objectId;
})
});

it('Make Contract Call', async () => {
const destinationChain = 'Destination Chain';
Expand All @@ -212,12 +211,7 @@ describe('Axelar Gateway', () => {

await builder.moveCall({
target: `${packageId}::gateway::call_contract`,
arguments: [
channel,
destinationChain,
destinationAddress,
payload,
],
arguments: [channel, destinationChain, destinationAddress, payload],
typeArguments: [],
});

Expand All @@ -229,9 +223,8 @@ describe('Axelar Gateway', () => {
payload: arrayify(payload),
payload_hash: keccak256(payload),
source_id: channel,
}
})
},
});
});
})

});
});
13 changes: 8 additions & 5 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ async function expectRevert(builder, keypair, error = {}) {
}

async function expectEvent(builder, keypair, eventData = {}) {
const response = await builder.signAndExecute(keypair, {showEvents: true});
const response = await builder.signAndExecute(keypair, { showEvents: true });

const event = response.events.find((event) => event.type == eventData.type);
const event = response.events.find((event) => event.type === eventData.type);

function compare(a, b) {
if(Array.isArray(a)) {
if (Array.isArray(a)) {
expect(a.length).to.equal(b.length);
for(let i=0; i<a.length; i++) {

for (let i = 0; i < a.length; i++) {
compare(a[i], b[i]);
}

return;
}

expect(a).to.equal(b);
}
for(const key of Object.keys(eventData.arguments)) {

for (const key of Object.keys(eventData.arguments)) {
compare(event.parsedJson[key], eventData.arguments[key]);
}
}
Expand Down

0 comments on commit 473205a

Please sign in to comment.