Skip to content

Commit

Permalink
rename some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Jan 20, 2025
1 parent 7ac8025 commit 46e65b2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 48 deletions.
20 changes: 10 additions & 10 deletions move/interchain_token_service/sources/types/chain_tracker.move
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct TrustedChain has store, drop {}

/// The interchain address tracker stores the trusted addresses for each chain.
public struct InterchainChainTracker has store {
trusted_addresses: Table<String, TrustedChain>,
trusted_chains: Table<String, TrustedChain>,
}

// -----------------
Expand All @@ -30,13 +30,13 @@ public(package) fun is_trusted_chain(
self: &InterchainChainTracker,
chain_name: String,
): bool {
self.trusted_addresses.contains(chain_name)
self.trusted_chains.contains(chain_name)
}

/// Create a new interchain address tracker.
public(package) fun new(ctx: &mut TxContext): InterchainChainTracker {
InterchainChainTracker {
trusted_addresses: table::new(ctx),
trusted_chains: table::new(ctx),
}
}

Expand All @@ -47,10 +47,10 @@ public(package) fun add_trusted_chain(
) {
assert!(chain_name.length() > 0, EEmptyChainName);

if (self.trusted_addresses.contains(chain_name)) {
if (self.trusted_chains.contains(chain_name)) {
abort EAlreadyTrusted
} else {
self.trusted_addresses.add(chain_name, TrustedChain{});
self.trusted_chains.add(chain_name, TrustedChain{});
};
events::trusted_address_added(chain_name);
}
Expand All @@ -60,7 +60,7 @@ public(package) fun remove_trusted_chain(
chain_name: String,
) {
assert!(chain_name.length() > 0, EEmptyChainName);
self.trusted_addresses.remove(chain_name);
self.trusted_chains.remove(chain_name);
events::trusted_address_removed(chain_name);
}

Expand All @@ -80,8 +80,8 @@ fun test_chain_tracker() {
assert!(self.is_trusted_chain(chain1) == true);
assert!(self.is_trusted_chain(chain2) == true);

assert!(self.trusted_addresses.contains(chain1));
assert!(self.trusted_addresses.contains(chain2));
assert!(self.trusted_chains.contains(chain1));
assert!(self.trusted_chains.contains(chain2));

self.remove_trusted_chain(chain1);
self.remove_trusted_chain(chain2);
Expand All @@ -90,8 +90,8 @@ fun test_chain_tracker() {
assert!(self.is_trusted_chain(chain1) == false);
assert!(self.is_trusted_chain(chain2) == false);

assert!(!self.trusted_addresses.contains(chain1));
assert!(!self.trusted_addresses.contains(chain2));
assert!(!self.trusted_chains.contains(chain1));
assert!(!self.trusted_chains.contains(chain2));

sui::test_utils::destroy(self);
}
Expand Down
14 changes: 4 additions & 10 deletions src/common/bcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,13 @@ function getITSStructs() {
const { Table, Bag, Channel } = getCommonStructs();
const { VersionControl } = getVersionControlStructs();

const InterchainAddressTracker = bcs.struct('InterchainAddressTracker', {
trusted_addresses: Table,
});

const TrustedAddresses = bcs.struct('TrustedAddresses', {
trusted_chains: bcs.vector(bcs.string()),
trusted_addresses: bcs.vector(bcs.string()),
const InterchainChainTracker = bcs.struct('InterchainChainTracker', {
trusted_chains: Table,
});

const InterchainTokenServiceV0 = bcs.struct('InterchainTokenService_v0', {
channel: Channel,
address_tracker: InterchainAddressTracker,
address_tracker: InterchainChainTracker,
unregistered_coin_types: Table,
unregistered_coins: Bag,
registered_coin_types: Table,
Expand All @@ -291,9 +286,8 @@ function getITSStructs() {
});

return {
InterchainAddressTracker,
InterchainChainTracker,
InterchainTokenService,
TrustedAddresses,
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/bcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('BCS', () => {
it('should decode InterchainTokenService_v0 object successfully', () => {
const its = bcsStructs.its.InterchainTokenService.parse(fromHEX(hexData.InterchainTokenService_v0)).value;

checkIdAndSize(its.address_tracker.trusted_addresses, '270c7f8b9757b05777d3cbf98fa1bb197e1f5a18c8ff7a8ef16e80bedf39a67f');
checkIdAndSize(its.chain_tracker.trusted_chains, '270c7f8b9757b05777d3cbf98fa1bb197e1f5a18c8ff7a8ef16e80bedf39a67f');
checkIdAndSize(its.unregistered_coin_types, '00c101dbc800d8cf853e6d21c916aba7c92e4c2692527dc951c777dae15cf474');
checkIdAndSize(its.unregistered_coins, '44bacbed87a2d5f871ce96f3245a293b936fb287605330b3859649f3a2697668');
checkIdAndSize(its.registered_coin_types, '13bd4dc87b61a82ce5959e3ea8c3fed1e03d9c1f7246eef82722354d8e3c0d54');
Expand Down
3 changes: 1 addition & 2 deletions test/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('ITS', () => {

// Parameters for Trusted Addresses
const trustedSourceChain = 'Avalanche';
const trustedSourceAddress = hexlify(randomBytes(20));

async function setupGateway() {
calculateNextSigners(gatewayInfo, nonce);
Expand Down Expand Up @@ -186,7 +185,7 @@ describe('ITS', () => {
before(async () => {
await setupGateway();
await registerItsTransaction();
await setupTrustedAddresses(client, deployer, objectIds, deployments, [trustedSourceAddress], [trustedSourceChain]);
await setupTrustedAddresses(client, deployer, objectIds, deployments, [trustedSourceChain]);
});

describe('Interchain Token Transfer', () => {
Expand Down

This file was deleted.

11 changes: 3 additions & 8 deletions test/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,13 @@ const getSingletonChannelId = async (client, singletonObjectId) => {
return '0x' + data.channel.id;
};

async function setupTrustedAddresses(client, keypair, objectIds, deployments, trustedAddresses, trustedChains = ['Ethereum']) {
async function setupTrustedAddresses(client, keypair, objectIds, deployments, trustedChains = ['Ethereum']) {
// Set trusted addresses
const trustedAddressTxBuilder = new TxBuilder(client);

const trustedAddressesObject = await trustedAddressTxBuilder.moveCall({
target: `${deployments.interchain_token_service.packageId}::trusted_addresses::new`,
arguments: [trustedChains, trustedAddresses],
});

await trustedAddressTxBuilder.moveCall({
target: `${deployments.interchain_token_service.packageId}::interchain_token_service::set_trusted_addresses`,
arguments: [objectIds.its, objectIds.itsOwnerCap, trustedAddressesObject],
target: `${deployments.interchain_token_service.packageId}::interchain_token_service::add_trusted_chains`,
arguments: [objectIds.its, objectIds.itsOwnerCap, trustedChains],
});

const trustedAddressResult = await trustedAddressTxBuilder.signAndExecute(keypair);
Expand Down

0 comments on commit 46e65b2

Please sign in to comment.