Skip to content

Commit

Permalink
feat: add test for sender sends coin without batch_id
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Aug 5, 2024
1 parent cd29822 commit 6f1f09d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions clients/apps/nodejs/test/tb04-simple-lightning-latch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,65 @@ describe('TB04 - Lightning Latch', function() {
console.error('Error:', error);
expect(error.message).to.include('failed');
}
})
})

context('Statecoin sender sends coin without batch_id (receiver should still be able to receive, but no pre-image revealed)', () => {
it('should complete successfully', async () => {

// await removeDatabase();
const clientConfig = client_config.load();
let wallet_1_name = "w_ln_11";
let wallet_2_name = "w_ln_12";
await createWallet(clientConfig, wallet_1_name);
await createWallet(clientConfig, wallet_2_name);

const token = await mercurynodejslib.newToken(clientConfig, wallet_1_name);
const tokenId = token.token_id;

const amount = 10000;
const depositInfo = await mercurynodejslib.getDepositBitcoinAddress(clientConfig, wallet_1_name, amount);

const tokenList = await mercurynodejslib.getWalletTokens(clientConfig, wallet_1_name);
const usedToken = tokenList.find(token => token.token_id === tokenId);

expect(usedToken.spent).is.true;

await depositCoin(clientConfig, wallet_1_name, amount, depositInfo);

const listCoins = await mercurynodejslib.listStatecoins(clientConfig, wallet_1_name);

expect(listCoins.length).to.equal(1);

const coin = listCoins[0];

expect(coin.status).to.equal(CoinStatus.CONFIRMED);

const paymentHash = await mercurynodejslib.paymentHash(clientConfig, wallet_1_name, coin.statechain_id);

const transferAddress = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin.statechain_id, transferAddress.transfer_receive, false, null);

let transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_2_name);

expect(transferReceiveResult.isThereBatchLocked).is.true;
expect(transferReceiveResult.receivedStatechainIds).empty;

await mercurynodejslib.confirmPendingInvoice(clientConfig, wallet_1_name, coin.statechain_id);

transferReceiveResult = await mercurynodejslib.transferReceive(clientConfig, wallet_2_name);

expect(transferReceiveResult.isThereBatchLocked).is.false;
expect(transferReceiveResult.receivedStatechainIds).not.empty;

const { preimage } = await mercurynodejslib.retrievePreImage(clientConfig, wallet_1_name, coin.statechain_id, paymentHash.batchId);

const hash = crypto.createHash('sha256')
.update(Buffer.from(preimage, 'hex'))
.digest('hex')

expect(hash).to.equal(paymentHash.hash);
})
})
})

0 comments on commit 6f1f09d

Please sign in to comment.