美文网首页
besu合约测试

besu合约测试

作者: 张亚伦 | 来源:发表于2021-04-02 13:30 被阅读0次

    验证三个点:

    • 共有合约:是否可以进行私有交易
    • 私有合约:是否可以进行共有交易
    • 私有合约:是否可以部分方进行交易,类似quorum
    1. 验证共有合约是否可以进行私有交易
      结果:不支持公有合约执行私有交易
    • 私有交易执行公有合约:不支持
    Waiting for transaction to be mined ...
    Member1 value from deployed contract is: 0x
    
    

    2.验证私有合约是否可以进行共有交易
    结果:不支持私有合约执行共有交易

    • 公有交易调用私有合约:不支持
    async function queryContract(deployedContractAddress) {
        const web3 = new Web3(besu.member1.url);
        const simpleContract = new web3.eth.Contract(abi, deployedContractAddress);
        // query Contract
        simpleContract.methods
            .value()
            .call()
            .then(console.log)
            .catch(console.log);
    
    }
    async function main() {
        //合约地址  私有:0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099   公共:"0x9720f1C2eFd99D9EE1287f70f716F13c5912B263"
        const contractAddress = "0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099";//
        queryContract(contractAddress)
        //invoke
        // invokeContract(contractAddress)
    }
    
    #output:
    Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
    
    1. 验证私有合约是否支持部分参与方进行交易:
      结果:私有交易invoke和query时privatefor必须要与部署合约时的节点相匹配;

    验证示例步骤:

    • 部署三个节点,正常情况执行invoke和query操作:(privatefor包含3个节点)
    D:\mygithub\tasks\besu\quorum-test-network\quorum-test-network\smart_contracts\scripts>node server.js
    web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    Creating contract...
    Getting contractAddress from txHash:  0x2d3bbddbf8b30c5b16d332b64c6168ad3440dd01a0ae40c05b1f77ff5302721c
    Waiting for transaction to be mined ...
    Private Transaction Receipt: [object Object]
    Contract deployed at address: 0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099
    functionParams:{"to":"0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099","data":"0x6057361d000000000000000000000000000000000000000000000000000000000000002e","privateFrom":"A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=","privateFor":["k2zXEin4Ip/qBGlRkJejnGWdP9cjkK+DAvKNW31L2C8=","Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs="],"privateKey":"8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"}
    Transaction hash: 0x567e19f6961124ec51a114a9a5029ce2cc8ecb40e71ffab079181fa4ac4df433
    Waiting for transaction to be mined ...
    web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-shh package will be deprecated in version 1.3.5 and will no longer be supported.
    web3-bzz package will be deprecated in version 1.3.5 and will no longer be supported.
    Transaction hash: 0x4b9bdcca3e70a7287cc8450c37eb8fafb00c268f160305cc1ce282bd805c6b81
    Waiting for transaction to be mined ...
    Transaction hash: 0xf4250af20dfc7079c328b69611998005a9cd3284827e67a17c228cc2f886074d
    Waiting for transaction to be mined ...
    Transaction hash: 0x93c071ff33732939e56f68294ed1afdfb5948664ee94ec25c2457b2383c2949b
    Waiting for transaction to be mined ...
    Member1 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002e
    Member2 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002e
    Member3 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002e
    
    • query操作:验证privatefor去掉节点三的publickey是否可以查询到结果:答案为false
    ##在节点2执行:privatefor仅仅包含1的publickey
    callContract.getValueAtAddressOnNode(besu.member2.url, "Member2", deployedContractAddress, orion.member2.publicKey, [orion.member1.publicKey], besu.member2.privateKey).then(console.log);
    
    //output:
    Transaction hash: 0x00f858f4f77881c1b8922e091140f42eb16c8cddc6fde650f98e3c0656ff83a8
    Waiting for transaction to be mined ...
    Member2 value from deployed contract is: 0x
    
    #在节点2执行:privatefor包含1和3的publickey
    callContract.getValueAtAddressOnNode(besu.member2.url, "Member2", deployedContractAddress, orion.member2.publicKey, [orion.member1.publicKey, orion.member3.publicKey], besu.member2.privateKey).then(console.log);
    //output:
    Transaction hash: 0xc52e3d75fedf4110f0bec01c3b9c9068b801e19e744cd33f913a0af3bcc8c749
    Waiting for transaction to be mined ...
    Member2 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002e
    
    • invoke操作: 验证privatefor去掉节点三的publickey是否可以invoke:答案为false
    # 在节点1执行:privatefor仅仅包含3的publickey,结果无法上链。
    const functionParams = {
            to: deployedContractAddress,
            data: functionAbi.signature + functionArgs,
            privateFrom: orion.member1.publicKey,
            privateFor: [orion.member3.publicKey],
            privateKey: besu.member1.privateKey
        };
    
    //output:
    Transaction hash: 0xa87e4a655aff1f63881cc913901a535a3d59ba071e801131dfdf6d84fc2f957c
    Transaction hash: 0x48926e018468a7667645adebb2a7576d2fa16e52a11669891b4bd188436f41dc
    Waiting for transaction to be mined ...
    Waiting for transaction to be mined ...
    Member2 value from deployed contract is: 0x000000000000000000000000000000000000000000000000000000000000002e
    
    
    # 在节点1执行:privatefor包含2和3的publickey,结果可以正常上链。
    const functionParams = {
            to: deployedContractAddress,
            data: functionAbi.signature + functionArgs,
            privateFrom: orion.member1.publicKey,
            privateFor: [orion.member3.publicKey, orion.member2.publicKey],
            privateKey: besu.member1.privateKey
        };
    
    //output:
    Transaction hash: 0xc4c8acc7daa20e01630167b22f6a20aa2db04b2a6fdb50871affcb65d30ab506
    Waiting for transaction to be mined ...
    blockHash":"0x8f004660af7111dea4ce5ae55a306f5914b3807155d6a7149f812aa6742bd9d4","blockNumber":"0x9786","transactionIndex":"0x0"}
    {
      from: '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73',
      to: '0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099',
      output: '0x',
      commitmentHash: '0xc4c8acc7daa20e01630167b22f6a20aa2db04b2a6fdb50871affcb65d30ab506',
      transactionHash: '0x0070d7678023b2077efa1e53dca4bad4403ef343ae6ddcf94545c7293d887c01',
      privateFrom: 'A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=',
      privateFor: [
        'k2zXEin4Ip/qBGlRkJejnGWdP9cjkK+DAvKNW31L2C8=',
        'Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs='
      ],
      status: '0x1',
      logs: [
        {
          address: '0x4e15c5e3897ae1e23054da64d9ffc118d2fe7099',
          topics: [Array],
          data: '0x000000000000000000000000fe3b557e8fb62b89f4916b721be55ceb828dbd730000000000000000000000000000000000000000000000000000000000000002',
          blockNumber: '0x9786',
          transactionHash: '0xc4c8acc7daa20e01630167b22f6a20aa2db04b2a6fdb50871affcb65d30ab506',
          transactionIndex: '0x0',
          blockHash: '0x8f004660af7111dea4ce5ae55a306f5914b3807155d6a7149f812aa6742bd9d4',
          logIndex: '0x0',
          removed: false
        }
      ],
      logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000002001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000',
      blockHash: '0x8f004660af7111dea4ce5ae55a306f5914b3807155d6a7149f812aa6742bd9d4',
      blockNumber: '0x9786',
      transactionIndex: '0x0'
    }
    
    

    相关文章

      网友评论

          本文标题:besu合约测试

          本文链接:https://www.haomeiwen.com/subject/veafkltx.html