Tact 智能合约测试中交易状态不一致

问题描述 投票:0回答:1

我正在用 Tact 语言测试智能合约,并遇到交易状态报告问题。当使用 printTransactionFees(result.transactions) 检查交易详细信息时,表明交易失败并出现预期的退出代码。但是,我对交易状态的断言检查并未按预期运行:

expect(result.transactions).toHaveTransaction({
    from: hashedTimeLockTON.address,
    to: receiver,
    success: false,
});

此断言本应确认交易失败,但它通过指示 success: true 来失败。尽管存在失败退出代码,但交易仍被标记为成功,是否存在导致这种差异的根本原因?这可能是什么原因造成的?这种情况下如何准确查看交易状态?

任何有关解决此问题的见解或建议将不胜感激。预先感谢您的帮助!

transactions blockchain smartcontracts ton tact
1个回答
0
投票

通过查看toHaveTransaction的实现代码可以知道,底层使用的是Arrays.some方法,所以只要其中一个数组为true,则全部为true。这是一个缺陷。我认为底层应该更好地使用every方法。

function compareTransactionForTest(subject, cmp) {
    if (Array.isArray(subject)) {
        return {
            pass: subject.some(tx => compareTransaction(flattenTransaction(tx), cmp)),
            posMessage: ((subj, cmp) => `Expected ${(0, node_inspect_extracted_1.inspect)(subj.map(tx => flattenTransaction(tx)))} to contain a transaction that matches pattern ${(0, node_inspect_extracted_1.inspect)(cmp)}`).bind(undefined, subject, cmp),
            negMessage: ((subj, cmp) => `Expected ${(0, node_inspect_extracted_1.inspect)(subj.map(tx => flattenTransaction(tx)))} NOT to contain a transaction that matches pattern ${(0, node_inspect_extracted_1.inspect)(cmp)}, but it does`).bind(undefined, subject, cmp),
        };
    }
    else {
        try {
            const flat = flattenTransaction(subject);
            return {
                pass: compareTransaction(flat, cmp),
                posMessage: ((flat, cmp) => `Expected ${(0, node_inspect_extracted_1.inspect)(flat)} to match pattern ${(0, node_inspect_extracted_1.inspect)(cmp)}`).bind(undefined, flat, cmp),
                negMessage: ((flat, cmp) => `Expected ${(0, node_inspect_extracted_1.inspect)(flat)} NOT to match pattern ${(0, node_inspect_extracted_1.inspect)(cmp)}, but it does`).bind(undefined, flat, cmp),
            };
        }
        catch (e) {
            if (subject.transactions !== undefined) {
                console.warn('It seems that a SendMessageResult is being used for this comparison. Please make sure to pass `result.transactions` instead of just `result` into the matcher.');
            }
            throw e;
        }
    }
}
exports.compareTransactionForTest = compareTransactionForTest;
© www.soinside.com 2019 - 2024. All rights reserved.