Skip to content

Commit

Permalink
feat: remove the constructor from InterhcainAddressTracker (#115)
Browse files Browse the repository at this point in the history
feat: remove the constructor from InterhcainAddressTracker to make it easier r to be upgradable. (#114)

* remove the constructor from InterhcainAddressTracker to make it easier to be upgradable.

* removed unused test

* prettier

* made isTrustedAddress public

* bumped package version

* chore(npm): version bump

---------

Co-authored-by: Kiryl Yermakou <rma4ok@gmail.com>
(cherry picked from commit f6ecc77)

Co-authored-by: Foivos <foivos@umich.edu>
  • Loading branch information
re1ro and Foivos authored Nov 3, 2023
1 parent 4bb60e6 commit 1865e37
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
4 changes: 3 additions & 1 deletion contracts/test/utils/TestInterchainAddressTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ contract TestInterchainAddressTracker is InterchainAddressTracker, Ownable {
string memory chainName_,
string[] memory trustedChainNames,
string[] memory trustedAddresses
) InterchainAddressTracker(chainName_) Ownable(msg.sender) {
) Ownable(msg.sender) {
_setChainName(chainName_);

if (_CHAIN_NAME_SLOT != bytes32(uint256(keccak256('interchain-address-tracker-chain-name')) - 1))
revert Invalid();

Expand Down
12 changes: 3 additions & 9 deletions contracts/utils/InterchainAddressTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ contract InterchainAddressTracker is IInterchainAddressTracker {
// bytes32(uint256(keccak256('interchain-address-tracker-chain-name')) - 1)
bytes32 internal constant _CHAIN_NAME_SLOT = 0x0e2c162a1f4b5cff9fdbd6b34678a9bcb9898a0b9fbca695b112d61688d8b2ac;

/**
* @dev Constructs the InterchainAddressTracker contract.
* @param chainName_ The name of the current chain.
*/
constructor(string memory chainName_) {
if (bytes(chainName_).length == 0) revert ZeroStringLength();

function _setChainName(string memory chainName_) internal {
StringStorage.set(_CHAIN_NAME_SLOT, chainName_);
}
}

/**
* @dev Gets the name of the chain this is deployed at
Expand Down Expand Up @@ -60,7 +54,7 @@ contract InterchainAddressTracker is IInterchainAddressTracker {
* @param address_ Address of the sender
* @return bool true if the sender chain/address are trusted, false otherwise
*/
function isTrustedAddress(string calldata chain, string calldata address_) external view returns (bool) {
function isTrustedAddress(string calldata chain, string calldata address_) public view returns (bool) {
bytes32 addressHash = keccak256(bytes(address_));

return addressHash == trustedAddressHash(chain);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelar-network/axelar-gmp-sdk-solidity",
"version": "5.6.1",
"version": "5.6.2",
"description": "Solidity GMP SDK and utilities provided by Axelar for cross-chain development",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 1 addition & 15 deletions test/utils/InterchainAddressTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const { deployContract } = require('../utils.js');
describe('InterchainAddressTracker', () => {
let ownerWallet,
otherWallet,
interchainAddressTracker,
interchainAddressTrackerFactory;
interchainAddressTracker;

const otherRemoteAddress = 'any string as an address';
const otherChain = 'Other Name';
Expand All @@ -29,10 +28,6 @@ describe('InterchainAddressTracker', () => {
'TestInterchainAddressTracker',
[chainName, defaultChains, defaultAddresses],
);

interchainAddressTrackerFactory = await ethers.getContractFactory(
'InterchainAddressTracker',
);
});

it('check internal constants', async () => {
Expand All @@ -45,15 +40,6 @@ describe('InterchainAddressTracker', () => {
expect(await interchainAddressTracker.chainName()).to.equal(chainName);
});

it('Should revert on interchainAddressTracker deployment with invalid chain name', async () => {
await expect(
interchainAddressTrackerFactory.deploy(''),
).to.be.revertedWithCustomError(
interchainAddressTracker,
'ZeroStringLength',
);
});

it('Should get empty strings for the trusted address for unregistered chains', async () => {
expect(await interchainAddressTracker.trustedAddress(otherChain)).to.equal(
'',
Expand Down

0 comments on commit 1865e37

Please sign in to comment.