Skip to content

Commit

Permalink
Merge pull request #1982 from aeternity/channel-tests
Browse files Browse the repository at this point in the history
Improve channel tests and fixes
  • Loading branch information
davidyuk authored Jun 6, 2024
2 parents addc696 + 777e1a5 commit dba0fab
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 254 deletions.
3 changes: 1 addition & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
require: 'tooling/babel-register.js',
recursive: true,
extension: '.js,.ts',
timeout: process.env.NETWORK ? '500s' : '8s',
timeout: process.env.NETWORK ? '500s' : '6s',
ignore: 'test/environment/**',
exit: true // TODO: fix in state channel tests
}
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
node:
# TODO: switch to master after merging https://github.com/aeternity/aeternity/pull/4303
Expand Down
2 changes: 1 addition & 1 deletion src/channel/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default class Channel {
* })
* ```
*/
async leave(): Promise<{ channelId: Encoded.Bytearray; signedTx: Encoded.Transaction }> {
async leave(): Promise<{ channelId: Encoded.Channel; signedTx: Encoded.Transaction }> {
return this.enqueueAction(() => {
notify(this, 'channels.leave');
return { handler: handlers.awaitingLeave };
Expand Down
41 changes: 24 additions & 17 deletions src/channel/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type SignTx = (tx: Encoded.Transaction, options?: SignOptions) => (
/**
* @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}
*/
export interface ChannelOptions {
interface CommonChannelOptions {
existingFsmId?: Encoded.Bytearray;
/**
* Channel url (for example: "ws://localhost:3001")
Expand All @@ -74,7 +74,7 @@ export interface ChannelOptions {
/**
* Initial deposit in favour of the responder by the initiator
*/
pushAmount: number;
pushAmount: BigNumber | number;
/**
* Amount of coins the initiator has committed to the channel
*/
Expand All @@ -92,17 +92,9 @@ export interface ChannelOptions {
*/
ttl?: number;
/**
* Host of the responder's node
*/
host: string;
/**
* The port of the responders node
* The port of the responder's node
*/
port: number;
/**
* Participant role
*/
role: 'initiator' | 'responder';
/**
* How to calculate minimum depth (default: txfee)
*/
Expand All @@ -120,16 +112,16 @@ export interface ChannelOptions {
*/
gasPrice?: BigNumber | number;

signedTx?: string;
signedTx?: Encoded.Transaction;
/**
* Existing channel id (required if reestablishing a channel)
*/
existingChannelId?: string;
existingChannelId?: Encoded.Channel;
/**
* Offchain transaction (required if reestablishing a channel)
*/
offChainTx?: string;
reconnectTx?: string;
offChainTx?: Encoded.Transaction;
reconnectTx?: Encoded.Transaction;
/**
* The time waiting for a new event to be initiated (default: 600000)
*/
Expand Down Expand Up @@ -174,7 +166,6 @@ export interface ChannelOptions {
* Applicable only for responder (default: timeout_idle's value)
*/
timeoutAwaitingOpen?: number;
statePassword?: string;
/**
* Log websocket communication and state changes
*/
Expand All @@ -183,9 +174,25 @@ export interface ChannelOptions {
* Function which verifies and signs transactions
*/
sign: SignTxWithTag;
offchainTx?: string;
offchainTx?: Encoded.Transaction;
}

export type ChannelOptions = CommonChannelOptions & ({
/**
* Participant role
*/
role: 'initiator';
/**
* Host of the responder's node
*/
host: string;
} | {
/**
* Participant role
*/
role: 'responder';
});

export interface ChannelHandler extends Function {
enter?: Function;
}
Expand Down
5 changes: 4 additions & 1 deletion test/integration/MiddlewareSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ describe('MiddlewareSubscriber', () => {
});

it('fails to subscribe to invalid address', async () => {
let unsubscribe: (() => void) | undefined;
const promise = new Promise((resolve, reject) => {
middleware.subscribeObject('ak_test', (payload, error) => {
unsubscribe = middleware.subscribeObject('ak_test', (payload, error) => {
if (error != null) reject(error);
else resolve(payload);
});
});
await expect(promise).to.be.rejectedWith(_MiddlewareSubscriberError, 'invalid target: ak_test');
assertNotNull(unsubscribe);
unsubscribe();
});

async function ensureConnected(ms: _MiddlewareSubscriber): Promise<void> {
Expand Down
Loading

0 comments on commit dba0fab

Please sign in to comment.