-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from AbstractSDK/adair/0.25-update
Abstract 0.25
- Loading branch information
Showing
15 changed files
with
266 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@abstract-money/core": minor | ||
"@abstract-money/cosmwasm-utils": patch | ||
--- | ||
|
||
Update Abstract to 0.25 with account instantiation changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/core/src/utils/account-id/account-id-to-string.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { accountIdToString } from './account-id-to-string' | ||
|
||
describe('accountIdToString', () => { | ||
it('should convert a local account ID object to string', () => { | ||
const accountId = { | ||
chainName: 'neutrontestnet', | ||
seq: 42, | ||
trace: 'local' as const, | ||
} | ||
const result = accountIdToString(accountId) | ||
expect(result).toEqual('neutrontestnet-42') | ||
}) | ||
|
||
it('should convert a simple chain account ID object to string', () => { | ||
const accountId = { | ||
chainName: 'neutrontestnet', | ||
seq: 42, | ||
trace: 'local' as const, | ||
} | ||
const result = accountIdToString(accountId) | ||
expect(result).toEqual('neutrontestnet-42') | ||
}) | ||
|
||
it('should convert a multi-hop chain account ID object to string', () => { | ||
const accountId = { | ||
chainName: 'neutron', | ||
seq: 42, | ||
trace: { | ||
remote: ['osmosis'], | ||
}, | ||
} | ||
const result = accountIdToString(accountId) | ||
expect(result).toEqual('neutron>osmosis-42') | ||
}) | ||
|
||
it('should convert a complex multi-hop chain account ID object to string', () => { | ||
const accountId = { | ||
chainName: 'neutron', | ||
seq: 42, | ||
trace: { | ||
remote: ['juno', 'osmosis'], | ||
}, | ||
} | ||
const result = accountIdToString(accountId) | ||
expect(result).toEqual('neutron>osmosis>juno-42') | ||
}) | ||
|
||
it('should throw an error if seq is not a valid number', () => { | ||
const accountId = { | ||
chainName: 'neutron', | ||
seq: -1, | ||
trace: 'local' as const, | ||
} | ||
expect(() => accountIdToString(accountId)).toThrow( | ||
'Invalid account sequence: -1', | ||
) | ||
}) | ||
|
||
it('should throw an error if chainName is missing', () => { | ||
const accountId = { | ||
seq: 42, | ||
trace: 'local' as const, | ||
chainName: '', | ||
} | ||
expect(() => accountIdToString(accountId)).toThrow( | ||
'AccountId must have a chainName', | ||
) | ||
}) | ||
|
||
it('should throw an error if trace is not valid', () => { | ||
const accountId = { | ||
chainName: 'neutron', | ||
seq: 42, | ||
trace: { remote: [] }, | ||
} | ||
expect(() => accountIdToString(accountId)).toThrow( | ||
'Invalid remote trace: []', | ||
) | ||
}) | ||
|
||
it('should throw an error if trace is not valid', () => { | ||
const accountId = { | ||
chainName: 'neutron', | ||
seq: 42, | ||
trace: { remote: [''] }, | ||
} | ||
expect(() => accountIdToString(accountId)).toThrow( | ||
'Invalid remote trace: [""]', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/core/src/utils/account-id/string-to-account-id.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { stringToAccountId } from './string-to-account-id' | ||
|
||
describe('stringToAccountId', () => { | ||
it('should parse a local account ID with chainName', () => { | ||
const result = stringToAccountId('local-42', 'neutrontestnet') | ||
expect(result).toEqual({ | ||
chainName: 'neutrontestnet', | ||
seq: 42, | ||
trace: 'local', | ||
}) | ||
}) | ||
|
||
it('should throw an error for a local account ID without chainName', () => { | ||
expect(() => stringToAccountId('local-42')).toThrow( | ||
'chainName must be provided for local account ids', | ||
) | ||
}) | ||
|
||
it('should parse a simple chain account ID', () => { | ||
const result = stringToAccountId('neutrontestnet-42') | ||
expect(result).toEqual({ | ||
chainName: 'neutrontestnet', | ||
seq: 42, | ||
trace: 'local', | ||
}) | ||
}) | ||
|
||
it('should parse a multi-hop chain account ID', () => { | ||
const result = stringToAccountId('osmosis>neutron-42') | ||
expect(result).toEqual({ | ||
chainName: 'osmosis', | ||
seq: 42, | ||
trace: { | ||
remote: ['neutron'], | ||
}, | ||
}) | ||
}) | ||
|
||
it('should parse a multi-hop chain account ID with provided chain', () => { | ||
const result = stringToAccountId('osmosis>neutron-42', 'osmosis') | ||
expect(result).toEqual({ | ||
chainName: 'osmosis', | ||
seq: 42, | ||
trace: { | ||
remote: ['neutron'], | ||
}, | ||
}) | ||
}) | ||
|
||
it('should parse a complex multi-hop chain account ID', () => { | ||
const result = stringToAccountId('neutron>juno>osmosis-42') | ||
expect(result).toEqual({ | ||
chainName: 'neutron', | ||
seq: 42, | ||
trace: { | ||
remote: ['osmosis', 'juno'], | ||
}, | ||
}) | ||
}) | ||
|
||
it('should throw an error when the account string is invalid', () => { | ||
expect(() => stringToAccountId('invalidString')).toThrow( | ||
'Cannot find chain or sequence for account: invalidString', | ||
) | ||
}) | ||
|
||
it('should throw an error when source chain does not match provided chainName', () => { | ||
expect(() => stringToAccountId('neutrontestnet-42', 'osmosis')).toThrow( | ||
'chainName osmosis does not match chain in account id neutrontestnet-42', | ||
) | ||
}) | ||
|
||
it('should throw an error when account has no source chain in non-local accounts', () => { | ||
expect(() => stringToAccountId('>osmosis-42')).toThrow( | ||
'Invalid chain string in account id >osmosis-42', | ||
) | ||
}) | ||
}) |
Oops, something went wrong.