Skip to content

Commit

Permalink
chore: all single-node lightpush requests should now be expected to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Jan 17, 2025
1 parent b7d3192 commit 980801b
Showing 1 changed file with 23 additions and 165 deletions.
188 changes: 23 additions & 165 deletions packages/tests/tests/light-push/single_node/index.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
afterEachCustom,
beforeEachCustom,
generateRandomUint8Array,
MessageCollector,
ServiceNode,
tearDownNodes,
TEST_STRING
Expand All @@ -22,16 +21,16 @@ import {
TestShardInfo
} from "../utils.js";

describe("Waku Light Push: Single Node", function () {
// These tests are expected to fail as service nodes now require at least one more connected node: https://github.com/waku-org/nwaku/pull/2951/files

describe.only("Waku Light Push: Single Node: Fails as expected", function () {
// Set the timeout for all tests in this suite. Can be overwritten at test level
this.timeout(15000);
let waku: LightNode;
let nwaku: ServiceNode;
let messageCollector: MessageCollector;

beforeEachCustom(this, async () => {
[nwaku, waku] = await runNodes(this.ctx, TestShardInfo);
messageCollector = new MessageCollector(nwaku);

await nwaku.ensureSubscriptions([TestPubsubTopic]);
});
Expand All @@ -45,18 +44,9 @@ describe("Waku Light Push: Single Node", function () {
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: utf8ToBytes(testItem.value)
});
expect(pushResponse.successes.length).to.eq(1);

expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: testItem.value,
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
// Expect failure since node requires another connected node
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
});
});

Expand All @@ -67,73 +57,9 @@ describe("Waku Light Push: Single Node", function () {
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: utf8ToBytes(generateMessageText(i))
});
expect(pushResponse.successes.length).to.eq(1);
}

expect(
await messageCollector.waitForMessages(30, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);

for (let i = 0; i < 30; i++) {
messageCollector.verifyReceivedMessage(i, {
expectedMessageText: generateMessageText(i),
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
}
});

it("Throws when trying to push message with empty payload", async function () {
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: new Uint8Array()
});

expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.map((failure) => failure.error)).to.include(
ProtocolError.EMPTY_PAYLOAD
);
expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(false);
});

TEST_STRING.forEach((testItem) => {
it(`Push message with content topic containing ${testItem.description}`, async function () {
const customEncoder = createEncoder({
contentTopic: testItem.value,
pubsubTopic: TestPubsubTopic
});
const pushResponse = await waku.lightPush.send(
customEncoder,
messagePayload
);
expect(pushResponse.successes.length).to.eq(1);

expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedContentTopic: testItem.value,
expectedPubsubTopic: TestPubsubTopic
});
});
});

it("Fails to push message with empty content topic", async function () {
try {
createEncoder({ contentTopic: "" });
expect.fail("Expected an error but didn't get one");
} catch (error) {
expect((error as Error).message).to.equal(
"Content topic must be specified"
);
// Expect failure since node requires another connected node
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
}
});

Expand All @@ -148,62 +74,19 @@ describe("Waku Light Push: Single Node", function () {
customTestEncoder,
messagePayload
);
expect(pushResponse.successes.length).to.eq(1);

expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
});

it("Fails to push message with large meta", async function () {
const customTestEncoder = createEncoder({
contentTopic: TestContentTopic,
pubsubTopic: TestPubsubTopic,
metaSetter: () => new Uint8Array(105024) // see the note below ***
it("Fails to push message with empty payload", async function () {
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: new Uint8Array()
});

// *** note: this test used 10 ** 6 when `nwaku` node had MaxWakuMessageSize == 1MiB ( 1*2^20 .)
// `nwaku` establishes the max lightpush msg size as `const MaxRpcSize* = MaxWakuMessageSize + 64 * 1024`
// see: https://github.com/waku-org/nwaku/blob/07beea02095035f4f4c234ec2dec1f365e6955b8/waku/waku_lightpush/rpc_codec.nim#L15
// In the PR https://github.com/waku-org/nwaku/pull/2298 we reduced the MaxWakuMessageSize
// from 1MiB to 150KiB. Therefore, the 105024 number comes from substracting ( 1*2^20 - 150*2^10 )
// to the original 10^6 that this test had when MaxWakuMessageSize == 1*2^20

const pushResponse = await waku.lightPush.send(
customTestEncoder,
messagePayload
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.map((failure) => failure.error)).to.include(
ProtocolError.EMPTY_PAYLOAD
);

if (nwaku.type == "go-waku") {
expect(pushResponse.successes.length).to.eq(1);
expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
} else {
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.map((failure) => failure.error)).to.include(
ProtocolError.REMOTE_PEER_REJECTED
);
expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(false);
}
});

it("Push message with rate limit", async function () {
Expand All @@ -221,18 +104,8 @@ describe("Waku Light Push: Single Node", function () {
payload: utf8ToBytes(messageText),
rateLimitProof: rateLimitProof
});
expect(pushResponse.successes.length).to.eq(1);

expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
});

[
Expand All @@ -245,19 +118,8 @@ describe("Waku Light Push: Single Node", function () {
payload: utf8ToBytes(messageText),
timestamp: new Date(testItem)
});
expect(pushResponse.successes.length).to.eq(1);

expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(true);
messageCollector.verifyReceivedMessage(0, {
expectedMessageText: messageText,
expectedTimestamp: testItem,
expectedContentTopic: TestContentTopic,
expectedPubsubTopic: TestPubsubTopic
});
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
});
});

Expand All @@ -266,7 +128,8 @@ describe("Waku Light Push: Single Node", function () {
const pushResponse = await waku.lightPush.send(TestEncoder, {
payload: bigPayload
});
expect(pushResponse.successes.length).to.greaterThan(0);
expect(pushResponse.successes.length).to.eq(0);
expect(pushResponse.failures?.length).to.be.greaterThan(0);
});

it("Fails to push message bigger that 1MB", async function () {
Expand All @@ -279,10 +142,5 @@ describe("Waku Light Push: Single Node", function () {
expect(pushResponse.failures?.map((failure) => failure.error)).to.include(
ProtocolError.SIZE_TOO_BIG
);
expect(
await messageCollector.waitForMessages(1, {
pubsubTopic: TestPubsubTopic
})
).to.eq(false);
});
});

0 comments on commit 980801b

Please sign in to comment.