松露测试似乎没有在“成功”之前完成,并且不会等待发送的 tx

问题描述

从昨晚开始我就一直头疼的问题,

我的 truffle (v5.2.3) 测试文件执行两 (2) 个测试,依次call() 然后实际发送交易以对我的智能合约的存储进行持久更改。这些测试如下(对于转储的文件很抱歉,我已经尽可能地最小化了):

const PassportManager = artifacts.require("PassportManager");

contract("PassportManager",accounts => {
    it("should initialize a new passport linked with the current user's address",() => {
        let this_address = accounts[0];
        let this_nickname = "John Doe";
        let Meta;
        
    return PassportManager.deployed()
        .then(instance => {
            Meta = instance;
            console.log("Test1 on PassportManager address: " + Meta.address);
            return Meta.initPassport.call(this_nickname);
        })
        .then(returned_tuple => {
            assert.equal(returned_tuple[0],this_nickname,"Nickname,passed and returned by PassportManager.initPassport(),should match!");
            assert.equal(returned_tuple[1],this_address,"Controller address,should match!");
            //If we're here,it means the prevIoUs call() has succeeded. Now,//let's take things up a notch and let's actually send a transaction that changes the state of the blockchain.
            //Remember: We can't check for return values with a transaction,we have to debug the tx id manually.
            //#NOTE: We passed an extra parameter here. For more info on this special parameter object,check out:
            //https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts#making-a-transaction
            const result = Meta.initPassport.sendTransaction(this_nickname,{from: accounts[0]});
            result.on('transactionHash',(hash) => {
                console.log('TxHash',hash);
            });
        });
    });
    
    it("should add an identity file sha256 hash to a controlled passport",() => {
        let this_address = accounts[0];
        let doc_hash = "0x21f3a9de43f07d855f49b946a10c30df432e8af95311435f77daf894216dcd41";
        let Meta;
        
    return PassportManager.deployed()
        .then(instance => {
            Meta = instance;
            console.log("Test2 on PassportManager address: " + Meta.address);
            return Meta.addIDFiletoPassport.call(this_address,doc_hash);
        })
        .then(returned_tuple => {
            assert.equal(returned_tuple[0],"Passport controller,passed and returned by PassportManager.addIDFiletoPassport(),doc_hash,"Document hash (bytes32),should match!");
            assert.equal(returned_tuple[2],1,"Trust score of newly added doc_hash should be 1!");
            //Now let's actually pass a concrete,actuallly persistent transaction instead of a call.
            const result = Meta.addIDFiletoPassport.sendTransaction(this_address,hash);
            });
            console.log("what the hell");
        });
    });
    
  /*it("return false",() => {
    assert(0==1);
  });
  */
});

一个测试调用,然后发送一个交易就好了!在我每次运行 truffle test 时,我都会在控制台中获得不错的预期日志结果:

Test1 on PassportManager address: 0x871bbABdAeA0721FEB5529A07119edC7f05aB508
    ✓ should initialize a new passport linked with the current user's address (71ms)
TxHash 0x0760cb2738da2a21cc404e0627e1008599fe81f2c3a6914a1b06ff712dc8adca

现在它继续进行第二次测试,由于某种原因它不发送交易,即使调用成功

Test2 on PassportManager address: 0x871bbABdAeA0721FEB5529A07119edC7f05aB508
what the hell
    ✓ should add an identity file sha256 hash to a controlled passport (58ms)

断言成功,我的合约调用返回的结果被记录,我们甚至到达了BELOW的沮丧的小what the hell,但我从来没有得到类似于第一个 sendTransaction 测试的发送交易的 TxHash!

更奇怪的是,如果我添加第三个 it() 测试,它会按预期工作: 从我的测试块中取消对 it() 的注释,然后瞧瞧:

it("return false",() => { assert(0==1); });

从昨天开始,我就一直在纠结这个问题,我闻到了某种并发/时间问题。有没有办法控制发送交易的顺序,或者等待一个交易被提交和挖掘,然后再继续测试?
打印 Test2 on PassportManager address: 0x87465190eCBa7C287143f07653462a87464b1AbA what the hell ✓ should add an identity file sha256 hash to a controlled passport (119ms) 1) return false TxHash 0x9226311347487d294b0bcf5bc1f535636fe886f08dfa327f15de43318aad37d7 Events emitted during test: --------------------------- /* I even get proper emitted event data from my contract! */ --------------------------- s 的奇怪序列(例如,在测试 2 之前的第三个测试失败实际上打印出 txHash 和事件数据) 可能指向类似的东西,但我认为console.log() 块将确保我们正在等待 tx 被挖掘!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...