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

Commit

Permalink
♻️ Apply format
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Nov 16, 2022
1 parent 9832315 commit 39d8f87
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
import { PrefixedStateReadWriter } from '../../../../src/state_machine/prefixed_state_read_writer';
import { InMemoryPrefixedStateDB } from '../../../../src/testing/in_memory_prefixed_state';
import { ChannelDataStore } from '../../../../src/modules/interoperability/stores/channel_data';
import { outboxRootSchema, OutboxRootStore } from '../../../../src/modules/interoperability/stores/outbox_root';
import {
outboxRootSchema,
OutboxRootStore,
} from '../../../../src/modules/interoperability/stores/outbox_root';
import {
TerminatedOutboxAccount,
TerminatedOutboxStore,
Expand Down Expand Up @@ -964,60 +967,73 @@ describe('Base interoperability internal method', () => {
};

beforeEach(async () => {
await interopMod.stores
.get(ChannelDataStore)
.set(methodContext, txParams.sendingChainID, {
...channelData,
});
await interopMod.stores.get(ChannelDataStore).set(methodContext, txParams.sendingChainID, {
...channelData,
});
});

it('should reject when inbox root is empty but partnerchain outbox root does not match', async () => {
await expect(mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
certificate: Buffer.alloc(0),
})).rejects.toThrow('Inbox root does not match partner chain outbox root');
await expect(
mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
certificate: Buffer.alloc(0),
}),
).rejects.toThrow('Inbox root does not match partner chain outbox root');
});

it('should reject when certificate state root does not contain valid inclusion proof for inbox update', async () => {
jest.spyOn(SparseMerkleTree.prototype, 'verify').mockResolvedValue(false);

await expect(mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
})).rejects.toThrow('Invalid inclusion proof for inbox update');
await expect(
mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
}),
).rejects.toThrow('Invalid inclusion proof for inbox update');
});

it('should resolve when certificate is empty and inbox root matches partner outbox root', async () => {
jest.spyOn(SparseMerkleTree.prototype, 'verify').mockResolvedValue(false);
jest.spyOn(regularMerkleTree, 'calculateRootFromRightWitness').mockReturnValue(channelData.partnerChainOutboxRoot);
jest
.spyOn(regularMerkleTree, 'calculateRootFromRightWitness')
.mockReturnValue(channelData.partnerChainOutboxRoot);

await expect(mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
certificate: Buffer.alloc(0),
})).resolves.toBeUndefined();
await expect(
mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
certificate: Buffer.alloc(0),
}),
).resolves.toBeUndefined();
});

it('should resolve when certificate provides valid inclusion proof', async () => {
const nextRoot = cryptoUtils.getRandomBytes(32);
jest.spyOn(SparseMerkleTree.prototype, 'verify').mockResolvedValue(true);
jest.spyOn(regularMerkleTree, 'calculateRootFromRightWitness').mockReturnValue(nextRoot);

await expect(mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
})).resolves.toBeUndefined();
await expect(
mainchainInteroperabilityInternalMethod.verifyPartnerChainOutboxRoot(context, {
...txParams,
}),
).resolves.toBeUndefined();

const outboxKey = Buffer.concat([interopMod.stores.get(OutboxRootStore).key, cryptoUtils.hash(txParams.sendingChainID)]);
const outboxKey = Buffer.concat([
interopMod.stores.get(OutboxRootStore).key,
cryptoUtils.hash(txParams.sendingChainID),
]);
expect(SparseMerkleTree.prototype.verify).toHaveBeenCalledWith(
certificate.stateRoot,
[outboxKey],
{
siblingHashes: txParams.inboxUpdate.outboxRootWitness.siblingHashes,
queries: [{
key: outboxKey,
value: codec.encode(outboxRootSchema, { root: nextRoot }),
bitmap: txParams.inboxUpdate.outboxRootWitness.bitmap,
}],
queries: [
{
key: outboxKey,
value: codec.encode(outboxRootSchema, { root: nextRoot }),
bitmap: txParams.inboxUpdate.outboxRootWitness.bitmap,
},
],
},
)
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ describe('CrossChainUpdateCommand', () => {
).not.toHaveBeenCalled();
});

it('should call apply for ccm and add to the inbox where receivign chain is the main chain ', async () => {
it('should call apply for ccm and add to the inbox where receivign chain is the main chain', async () => {
executeContext = createTransactionContext({
chainID,
stateStore,
Expand All @@ -787,7 +787,7 @@ describe('CrossChainUpdateCommand', () => {
).toHaveBeenCalledTimes(3);
});

it('should call forward for ccm and add to the inbox where receivign chain is not the mainchain ', async () => {
it('should call forward for ccm and add to the inbox where receivign chain is not the mainchain', async () => {
executeContext = createTransactionContext({
chainID,
stateStore,
Expand Down

0 comments on commit 39d8f87

Please sign in to comment.