Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions smart_contract/contracts/Transactions.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

import "hardhat/console.sol";
// import "hardhat/console.sol";

contract Transactions {
uint256 transactionCount;


event Transfer(address from, address receiver, uint amount, string message, uint256 timestamp, string keyword);

struct TransferStruct {
Expand All @@ -19,8 +20,16 @@ contract Transactions {
}

TransferStruct[] transactions;


/// @notice Adds a transaction to the blockchain.
/// @param receiver The address receiving funds.
/// @param amount The amount being sent.
/// @param message A message associated with the transaction.
/// @param keyword A keyword for categorizing the transaction.
function addToBlockchain(address payable receiver, uint amount, string memory message, string memory keyword) public {
require(receiver != address(0), "Invalid receiver address");
require(amount > 0, "Amount must be greater than 0");

transactionCount += 1;
transactions.push(TransferStruct(msg.sender, receiver, amount, message, block.timestamp, keyword));

Expand Down
47 changes: 33 additions & 14 deletions smart_contract/test/sample-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();

expect(await greeter.greet()).to.equal("Hello, world!");

const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

// wait until the transaction is mined
await setGreetingTx.wait();

expect(await greeter.greet()).to.equal("Hola, mundo!");
describe("Transactions", function () {
let transactions
beforeEach( async()=>{
const Transactions = await ethers.getContractFactory("Transactions");
transactions = await Transactions.deploy();
})
it("Should reject zero address", async function () {

// await transactions.deployed();
const zeroAddress = ethers.ZeroAddress
// await expect(transactions.addToBlockchain(zeroAddress, 300,"message", "keyword")).to.be.revertedWithCustomError(transactions,"Transactions__InvalidReceiver")
// Note: Changed the error checking syntax
await expect(
transactions.addToBlockchain(
ethers.constants.AddressZero, // Invalid address
100, "Hello", "Test"
)
).to.be.revertedWith("Invalid receiver address");
});
it("Should reject zero amount", async function () {
const Transactions = await ethers.getContractFactory("Transactions");
transactions = await Transactions.deploy();
// await transactions.deployed();
const zeroAddress = ethers.ZeroAddress
// await expect(transactions.addToBlockchain(zeroAddress, 300,"message", "keyword")).to.be.revertedWithCustomError(transactions,"Transactions__InvalidReceiver")
// Note: Changed the error checking syntax
const address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
await expect(
transactions.addToBlockchain(
address,
0, "Hello", "Test"
)
).to.be.revertedWith("Amount must be greater than 0");
});
});