-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
252 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal final class AccountIdTests: XCTestCase { | ||
internal func testParse() { | ||
XCTAssertEqual(try AccountId.fromString("0.0.1001"), AccountId(num: 1001)) | ||
} | ||
|
||
internal func testToFromBytesRoundtrip() { | ||
let accountId = AccountId(num: 1001) | ||
|
||
XCTAssertEqual(accountId, try AccountId.fromBytes(accountId.toBytes())) | ||
} | ||
|
||
internal func testFromEvmAddressString() { | ||
XCTAssertEqual( | ||
AccountId(evmAddress: "0x302a300506032b6570032100114e6abc371b82da"), | ||
try AccountId.fromString("0x302a300506032b6570032100114e6abc371b82da") | ||
) | ||
} | ||
|
||
internal func testToEvmAddressString() { | ||
XCTAssertEqual( | ||
"0x302a300506032b6570032100114e6abc371b82da", | ||
AccountId(evmAddress: "0x302a300506032b6570032100114e6abc371b82da").toString() | ||
) | ||
} | ||
|
||
internal func testGoodChecksumOnMainnet() throws { | ||
let accountId = try AccountId.fromString("0.0.123-vfmkw") | ||
try accountId.validateChecksums(on: .mainnet) | ||
} | ||
|
||
internal func testGoodChecksumOnTestnet() throws { | ||
let accountId = try AccountId.fromString("0.0.123-esxsf") | ||
try accountId.validateChecksums(on: .testnet) | ||
} | ||
|
||
internal func testGoodChecksumOnPreviewnet() throws { | ||
let accountId = try AccountId.fromString("0.0.123-ogizo") | ||
try accountId.validateChecksums(on: .previewnet) | ||
} | ||
|
||
internal func testToStringWithChecksum() { | ||
let client = Client.forTestnet() | ||
|
||
XCTAssertEqual( | ||
"0.0.123-esxsf", | ||
try AccountId.fromString("0.0.123").toStringWithChecksum(client) | ||
) | ||
} | ||
|
||
internal func testBadChecksumOnPreviewnet() { | ||
let accountId: AccountId = "0.0.123-ntjli" | ||
|
||
XCTAssertThrowsError(try accountId.validateChecksums(on: .previewnet)) | ||
} | ||
|
||
internal func testMalformedIdFails() { | ||
XCTAssertThrowsError(try AccountId.fromString("0.0.")) | ||
} | ||
|
||
internal func testMalformedChecksum() { | ||
XCTAssertThrowsError(try AccountId.fromString("0.0.123-ntjl")) | ||
} | ||
|
||
internal func testMalformedChecksum2() { | ||
XCTAssertThrowsError(try AccountId.fromString("0.0.123-ntjl1")) | ||
} | ||
|
||
internal func testMalformedAlias() { | ||
XCTAssertThrowsError( | ||
try AccountId.fromString( | ||
"0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777")) | ||
} | ||
internal func testMalformedAlias2() { | ||
XCTAssertThrowsError( | ||
try AccountId.fromString( | ||
"0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777g")) | ||
} | ||
internal func testMalformedAliasKey3() { | ||
XCTAssertThrowsError( | ||
try AccountId.fromString( | ||
"0.0.303a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777")) | ||
} | ||
|
||
internal func testFromStringAliasKey() { | ||
assertSnapshot( | ||
matching: try AccountId.fromString( | ||
"0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromStringEvmAddress() { | ||
assertSnapshot( | ||
matching: try AccountId.fromString("0x302a300506032b6570032100114e6abc371b82da"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromSolidityAddress() { | ||
assertSnapshot( | ||
matching: try AccountId.fromSolidityAddress("000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromSolidityAddress0x() { | ||
assertSnapshot( | ||
matching: try AccountId.fromSolidityAddress("0x000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromBytes() { | ||
assertSnapshot( | ||
matching: try AccountId.fromBytes(AccountId(num: 5005).toBytes()), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromBytesAlias() throws { | ||
let bytes = try AccountId.fromString( | ||
"0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777" | ||
).toBytes() | ||
assertSnapshot( | ||
matching: try AccountId.fromBytes(bytes), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromBytesEvmAddress() throws { | ||
let bytes = try AccountId.fromString("0x302a300506032b6570032100114e6abc371b82da").toBytes() | ||
|
||
assertSnapshot( | ||
matching: try AccountId.fromBytes(bytes), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testToSolidityAddress() { | ||
assertSnapshot( | ||
matching: try AccountId(num: 5005).toSolidityAddress(), | ||
as: .lines | ||
) | ||
} | ||
|
||
internal func testFromEvmAddress() { | ||
assertSnapshot( | ||
matching: try AccountId(evmAddress: .fromString("0x302a300506032b6570032100114e6abc371b82da")), | ||
as: .description | ||
) | ||
} | ||
} |
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,64 @@ | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal final class ContractIdTests: XCTestCase { | ||
internal func testParse() { | ||
assertSnapshot(matching: try ContractId.fromString("0.0.5005"), as: .description) | ||
} | ||
|
||
internal func testFromSolidityAddress() { | ||
assertSnapshot( | ||
matching: try ContractId.fromSolidityAddress("000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromSolidityAddress0x() { | ||
assertSnapshot( | ||
matching: try ContractId.fromSolidityAddress("0x000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromEvmAddress() { | ||
assertSnapshot( | ||
matching: try ContractId.fromEvmAddress(1, 2, "000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testFromEvmAddress0x() { | ||
assertSnapshot( | ||
matching: try ContractId.fromEvmAddress(1, 2, "0x000000000000000000000000000000000000138D"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testParseEvmAddress() { | ||
assertSnapshot( | ||
matching: try ContractId.fromString("1.2.98329e006610472e6b372c080833f6d79ed833cf"), | ||
as: .description | ||
) | ||
} | ||
|
||
internal func testToFromBytes() { | ||
let a: ContractId = "1.2.3" | ||
XCTAssertEqual(a, try .fromBytes(a.toBytes())) | ||
let b: ContractId = "1.2.0x98329e006610472e6B372C080833f6D79ED833cf" | ||
XCTAssertEqual(b, try .fromBytes(b.toBytes())) | ||
} | ||
|
||
internal func testToSolidityAddress() { | ||
assertSnapshot(matching: try ContractId(num: 5005).toSolidityAddress(), as: .lines) | ||
} | ||
|
||
internal func testToSolidityAddress2() { | ||
assertSnapshot( | ||
matching: try ContractId.fromEvmAddress(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf") | ||
.toSolidityAddress(), | ||
as: .lines | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromBytes.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromBytesAlias.1.txt
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 @@ | ||
0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromBytesEvmAddress.1.txt
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 @@ | ||
0x302a300506032b6570032100114e6abc371b82da |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromEvmAddress.1.txt
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 @@ | ||
0x302a300506032b6570032100114e6abc371b82da |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromSolidityAddress.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromSolidityAddress0x.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromStringAliasKey.1.txt
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 @@ | ||
0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testFromStringEvmAddress.1.txt
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 @@ | ||
0x302a300506032b6570032100114e6abc371b82da |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/AccountIdTests/testToSolidityAddress.1.txt
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 @@ | ||
000000000000000000000000000000000000138d |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testFromEvmAddress.1.txt
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 @@ | ||
1.2.0x000000000000000000000000000000000000138d |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testFromEvmAddress0x.1.txt
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 @@ | ||
1.2.0x000000000000000000000000000000000000138d |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testFromSolidityAddress.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testFromSolidityAddress0x.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testParse.1.txt
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 @@ | ||
0.0.5005 |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testParseEvmAddress.1.txt
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 @@ | ||
1.2.0x98329e006610472e6b372c080833f6d79ed833cf |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testToSolidityAddress.1.txt
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 @@ | ||
000000000000000000000000000000000000138d |
1 change: 1 addition & 0 deletions
1
Tests/HederaTests/__Snapshots__/ContractIdTests/testToSolidityAddress2.1.txt
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 @@ | ||
98329e006610472e6b372c080833f6d79ed833cf |