From b5c74a3336b7c781ee572cca94ed13dcec558089 Mon Sep 17 00:00:00 2001 From: myh <95896306+Anchor-x@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/TestDeviceManager.sol | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/TestDeviceManager.sol diff --git a/test/TestDeviceManager.sol b/test/TestDeviceManager.sol new file mode 100644 index 0000000..8f81b1e --- /dev/null +++ b/test/TestDeviceManager.sol @@ -0,0 +1,39 @@ +pragma solidity ^0.4.24; +// FIXME - cannot be resolved by truffle +import "truffle/Assert.sol"; +import "truffle/DeployedAddresses.sol"; +import "../contracts/DeviceManager.sol"; + +contract TestDeviceManager { + DeviceManager deviceManager = DeviceManager(DeployedAddresses.DeviceManager()); + uint constant createdDeviceId = 0; + + function testCreateDevice() public { + uint deviceId = deviceManager.createDevice( + sha256("identifier"), + sha256("metadata"), + sha256("firmware") + ); + + Assert.equal(deviceId, createdDeviceId, "New device should be recorded with ID of 0."); + } + + function testCreatedDeviceOwner() public { + address owner; + (owner,,,) = deviceManager.devices(createdDeviceId); + + Assert.equal(owner, this, "Created device should be recorded and owned by this address"); + } + + function testGetDevicesByOwner() public { + uint[] memory deviceIds = deviceManager.getDevicesByOwner(this); + uint[] memory expectedIds = new uint[](1); + expectedIds[0] = 0; + + Assert.equal( + keccak256(abi.encodePacked(deviceIds)), + keccak256(abi.encodePacked(expectedIds)), + "Only one device should have been created owned by this address" + ); + } +}