Skip to content

Commit

Permalink
fix(channel): channelId type, more accurate types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 17, 2024
1 parent 74db9bb commit 2b064d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/channel/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,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
12 changes: 6 additions & 6 deletions src/channel/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -120,16 +120,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 @@ -182,7 +182,7 @@ export interface ChannelOptions {
* Function which verifies and signs transactions
*/
sign: SignTxWithTag;
offchainTx?: string;
offchainTx?: Encoded.Transaction;
}

export interface ChannelHandler extends Function {
Expand Down
11 changes: 6 additions & 5 deletions test/integration/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ async function waitForChannel(channel: Channel): Promise<void> {
let initiatorCh: Channel;
let responderCh: Channel;
let responderShouldRejectUpdate: number | boolean;
let existingChannelId: Encoded.Bytearray;
let offchainTx: string;
let contractAddress: Encoded.ContractAddress;
let callerNonce: number;
let contract: Contract<{}>;
Expand Down Expand Up @@ -626,6 +624,8 @@ async function waitForChannel(channel: Channel): Promise<void> {
// TODO: check `initiatorAmountFinal` and `responderAmountFinal`
});

let existingChannelId: Encoded.Channel;
let offchainTx: Encoded.Transaction;
it('can leave a channel', async () => {
initiatorCh.disconnect();
responderCh.disconnect();
Expand All @@ -639,12 +639,11 @@ async function waitForChannel(channel: Channel): Promise<void> {
role: 'responder',
sign: responderSignTag,
});

await Promise.all([waitForChannel(initiatorCh), waitForChannel(responderCh)]);
initiatorCh.round(); // existingChannelRound
const result = await initiatorCh.leave();
result.channelId.should.be.a('string');
result.signedTx.should.be.a('string');
expect(result.channelId).to.satisfy((t: string) => t.startsWith('ch_'));
expect(result.signedTx).to.satisfy((t: string) => t.startsWith('tx_'));
existingChannelId = result.channelId;
offchainTx = result.signedTx;
});
Expand All @@ -654,6 +653,7 @@ async function waitForChannel(channel: Channel): Promise<void> {
...sharedParams,
role: 'initiator',
port: 3002,
// @ts-expect-error TODO: use existingChannelId instead existingFsmId
existingFsmId: existingChannelId,
offchainTx,
sign: initiatorSignTag,
Expand Down Expand Up @@ -1091,6 +1091,7 @@ async function waitForChannel(channel: Channel): Promise<void> {
await aeSdkInitiatior.sendTransaction(snapshotSoloTx);
});

// https://github.com/aeternity/protocol/blob/d634e7a3f3110657900759b183d0734e61e5803a/node/api/channels_api_usage.md#reestablish
it('can reconnect', async () => {
initiatorCh.disconnect();
responderCh.disconnect();
Expand Down

0 comments on commit 2b064d8

Please sign in to comment.