Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dhl/b463ce9a6bd09e87fe74c992d7958d53 to your computer and use it in GitHub Desktop.
Save dhl/b463ce9a6bd09e87fe74c992d7958d53 to your computer and use it in GitHub Desktop.
Demo of web3.shh.clearSubscriptions Bug
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>web3.shh.clearSubscriptions bug demo</title>
</head>
<body>
<script src="https://rawgit.com/ethereum/web3.js/1.0/dist/web3.min.js"></script>
<script>
const web3 = new Web3('ws://localhost:8546');
const TOPIC = '0x00627579';
console.group('TEST CASE 1: Calling web3.shh.clearSubscriptions() without active subscription');
try {
console.info('Expectation: Completes without error');
console.info('Actual outcome: Failed with TypeError');
console.info('Clearning subscriptions...');
web3.shh.clearSubscriptions();
} catch(err) {
console.error(err);
}
console.groupEnd();
console.group('TEST CASE 2: Calling web3.shh.clearSubscriptions() with an active subscription');
const mainAsync = async () => {
console.info('Expectation: Completes without error');
console.info('Actual outcome: Failed with TypeError\n');
const symKeyID = await web3.shh.generateSymKeyFromPassword('secure_password');
console.log(`Subscribing to topic ${TOPIC}`);
web3.shh.subscribe('messages', {
symKeyID: symKeyID,
topic: [TOPIC]
}, function(err, result, sub) {
console.log('We got a message! Clearing the active subcription now...');
console.warn('Calling web3.shh.clearSubscriptions() with an active subscription will also fail!');
web3.shh.clearSubscriptions();
});
console.log(`Subscribed to topic ${TOPIC}`);
console.log(`Posting message to topic ${TOPIC}`);
web3.shh.post({
symKeyID,
ttl: 60,
topic: TOPIC,
payload: 'hi'
}, function(err, result) {
if (err) {
console.error(err);
return;
}
})
}
console.groupEnd();
mainAsync().catch(console.error);
</script>
</body>
</html>
@semuelle
Copy link

See here for workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment