Untitled
unknown
javascript
2 years ago
1.2 kB
8
Indexable
Never
// Solidity Code snippet: uint256 transactionCount; struct TransferStruct { address sender; address receiver; uint amount; string message; uint256 timestamp; string keyword; } TransferStruct[] transactions; event Transfer(address from, address _who, uint amount, string message, uint256 timestamp, string keyword); function addToBlockchain(address payable _who, uint amount, string memory message, string memory keyword) public { transactionCount += 1; transactions.push(TransferStruct(msg.sender, _who, amount, message, block.timestamp, keyword)); emit Transfer(msg.sender, _who, amount, message, block.timestamp, keyword); } function getAllTransactions() public view returns (TransferStruct[] memory) { return transactions; } --------------------------------------------------------------------------------------- // Truffle Test file Snippet describe("Add to Blockchain", () => { it("should add transfer to the struct", async() => { const txBlock = await _contract.addToBlockchain(_who, _amount, message, keyword) }) })