2022-11-25 04:17:08 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
2022-11-28 03:43:03 +00:00
|
|
|
import "./Mappings.sol";
|
2022-11-25 04:17:08 +00:00
|
|
|
|
|
|
|
// exposes public functions for testing
|
|
|
|
contract TestMappings {
|
|
|
|
using Mappings for Mappings.Mapping;
|
|
|
|
|
|
|
|
event OperationResult(bool result);
|
|
|
|
|
|
|
|
Mappings.Mapping private _map;
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function totalCount() public view returns (uint256) {
|
|
|
|
return _map.count();
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function count(Mappings.KeyId key) public view returns (uint256) {
|
|
|
|
return _map.count(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function keyExists(Mappings.KeyId key) public view returns (bool) {
|
|
|
|
return _map.exists(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function valueExists(Mappings.KeyId key, Mappings.ValueId value)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (bool)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
return _map.exists(key, value);
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function keys() public view returns (Mappings.KeyId[] memory) {
|
|
|
|
return _map.keys();
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function values(Mappings.KeyId key)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
view
|
|
|
|
returns (Mappings.ValueId[] memory)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
return _map.values(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function insertKey(Mappings.KeyId key) public returns (bool success) {
|
|
|
|
success = _map.insertKey(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function insertValue(Mappings.KeyId key, Mappings.ValueId value)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
returns (bool success)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
success = _map.insertValue(key, value);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function insert(Mappings.KeyId key, Mappings.ValueId value)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
returns (bool success)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
success = _map.insert(key, value);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function deleteKey(Mappings.KeyId key) public returns (bool success) {
|
|
|
|
success = _map.deleteKey(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function deleteValue(Mappings.KeyId key,
|
|
|
|
Mappings.ValueId value)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
returns (bool success)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
success = _map.deleteValue(key, value);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
|
2022-11-28 03:39:11 +00:00
|
|
|
function clear(Mappings.KeyId key)
|
2022-11-25 04:17:08 +00:00
|
|
|
public
|
|
|
|
returns (bool success)
|
|
|
|
{
|
2022-11-28 03:39:11 +00:00
|
|
|
success = _map.clear(key);
|
2022-11-25 04:17:08 +00:00
|
|
|
emit OperationResult(success);
|
|
|
|
}
|
|
|
|
}
|