Solidity映射返回空值

Solidity mapping returning null values

基本上,我在智能合约中创建了一个映射来存储用户数据的哈希值。它从用户 ID 映射到哈希本身(bytes32 值)。我使用双 sha256 哈希并将其存储在具有上述 ID 的映射中。通过返回映射中 id 处的值来存储它的函数 returns 哈希。这个散列是正确的,这意味着至少它最初存储正确。但是,我有另一个函数可以从 id 中获取哈希值,它在 javascript 测试中总是 returns 空值。我想知道这是测试的问题还是合同本身的问题。

pragma solidity ^0.4.22;
contract UserStore {
    mapping(uint => bytes32) UserHashes; //User id to hash

    event HashStored (
        uint id,
        bytes32 original, 
        bytes32 hash
    );


    function HashData(bytes32 data) returns (bytes32){
        return sha256(abi.encodePacked(sha256(abi.encodePacked(data))));
    }


    function StoreHash(uint user_id,  bytes32 data) external view returns (bytes32){ 
        UserHashes[user_id] = HashData(data);
        HashStored(user_id, data, UserHashes[user_id]);
        return UserHashes[user_id];
    }

    /*
        Gets the hash from the blockchain.
    */
    function GetHash(uint u_id) view public returns (bytes32){
        return UserHashes[u_id];
    }
}

每次我运行这个测试,GetHash returns一个0值;

contract("Storage_Test", function(accounts) {

    const args = {user_id: 0,
                  data: "This is some security data",
                  group_id : 15,
                  user_ids  : [1,2,3,4,5],
                  num_accounts : 2
    }
    it("Hash Test: Multiple Storage and retrieving", async function() { return 
await UserStore.deployed()
    .then(async function(instance) {
        var temp = args.data;
        var _temp;
        for (i = 1; i < args.num_accounts; i++) {
            _temp = temp;
            temp = await instance.HashData.call(temp);
            //  console.log("Datahash: " + temp);
            result = await instance.StoreHash.call(i, _temp);
            //  console.log("Result:   " + result);
            assert.equal(result, temp, "Hash at " + i + " wasn't returned 
correctly");
        }
        temp = args.data;
        for (i= 1; i < args.num_accounts; i++) {
            temp = await instance.HashData.call(temp);
            result = await instance.GetHash.call(i);
            assert.equal( result, temp, "Hash at " + i + " wasn't stored 
correctly");
        }
    })
    }); 
});

instance.StoreHash.call(...) 更改为 instance.StoreHash.sendTransaction(...)call() 在本地运行函数而不是提交交易。结果是任何状态更改都不会持久化。