@@ -17,8 +17,8 @@ class EthereumContractTest: LocalTestCase {
1717 private static let overloadedFunctionsABI = " [{ \" inputs \" :[], \" stateMutability \" : \" nonpayable \" , \" type \" : \" constructor \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" uint256 \" , \" name \" : \" operation \" , \" type \" : \" uint256 \" },{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" contractAddress \" , \" type \" : \" address \" },{ \" indexed \" :true, \" internalType \" : \" uint256 \" , \" name \" : \" value \" , \" type \" : \" uint256 \" }], \" name \" : \" ContractCreated \" , \" type \" : \" event \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" bytes32 \" , \" name \" : \" dataKey \" , \" type \" : \" bytes32 \" }], \" name \" : \" DataChanged \" , \" type \" : \" event \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" uint256 \" , \" name \" : \" operation \" , \" type \" : \" uint256 \" },{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" to \" , \" type \" : \" address \" },{ \" indexed \" :true, \" internalType \" : \" uint256 \" , \" name \" : \" value \" , \" type \" : \" uint256 \" },{ \" indexed \" :false, \" internalType \" : \" bytes4 \" , \" name \" : \" selector \" , \" type \" : \" bytes4 \" }], \" name \" : \" Executed \" , \" type \" : \" event \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" previousOwner \" , \" type \" : \" address \" },{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" newOwner \" , \" type \" : \" address \" }], \" name \" : \" OwnershipTransferred \" , \" type \" : \" event \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" from \" , \" type \" : \" address \" },{ \" indexed \" :false, \" internalType \" : \" uint256 \" , \" name \" : \" value \" , \" type \" : \" uint256 \" },{ \" indexed \" :true, \" internalType \" : \" bytes32 \" , \" name \" : \" typeId \" , \" type \" : \" bytes32 \" },{ \" indexed \" :true, \" internalType \" : \" bytes \" , \" name \" : \" returnedValue \" , \" type \" : \" bytes \" },{ \" indexed \" :false, \" internalType \" : \" bytes \" , \" name \" : \" receivedData \" , \" type \" : \" bytes \" }], \" name \" : \" UniversalReceiver \" , \" type \" : \" event \" },{ \" anonymous \" :false, \" inputs \" :[{ \" indexed \" :true, \" internalType \" : \" address \" , \" name \" : \" sender \" , \" type \" : \" address \" },{ \" indexed \" :true, \" internalType \" : \" uint256 \" , \" name \" : \" value \" , \" type \" : \" uint256 \" }], \" name \" : \" ValueReceived \" , \" type \" : \" event \" },{ \" stateMutability \" : \" payable \" , \" type \" : \" fallback \" },{ \" inputs \" :[{ \" internalType \" : \" bytes32[] \" , \" name \" : \" dataKeys \" , \" type \" : \" bytes32[] \" }], \" name \" : \" getData \" , \" outputs \" :[{ \" internalType \" : \" bytes[] \" , \" name \" : \" dataValues \" , \" type \" : \" bytes[] \" }], \" stateMutability \" : \" view \" , \" type \" : \" function \" },{ \" inputs \" :[{ \" internalType \" : \" bytes32 \" , \" name \" : \" dataKey \" , \" type \" : \" bytes32 \" }], \" name \" : \" getData \" , \" outputs \" :[{ \" internalType \" : \" bytes \" , \" name \" : \" dataValue \" , \" type \" : \" bytes \" }], \" stateMutability \" : \" view \" , \" type \" : \" function \" },{ \" inputs \" :[], \" name \" : \" noInputFunction \" , \" outputs \" :[], \" stateMutability \" : \" nonpayable \" , \" type \" : \" function \" },{ \" inputs \" :[{ \" internalType \" : \" bytes32[] \" , \" name \" : \" dataKeys \" , \" type \" : \" bytes32[] \" },{ \" internalType \" : \" bytes[] \" , \" name \" : \" dataValues \" , \" type \" : \" bytes[] \" }], \" name \" : \" setData \" , \" outputs \" :[], \" stateMutability \" : \" nonpayable \" , \" type \" : \" function \" },{ \" inputs \" :[{ \" internalType \" : \" bytes32 \" , \" name \" : \" dataKey \" , \" type \" : \" bytes32 \" },{ \" internalType \" : \" bytes \" , \" name \" : \" dataValue \" , \" type \" : \" bytes \" }], \" name \" : \" setData \" , \" outputs \" :[], \" stateMutability \" : \" nonpayable \" , \" type \" : \" function \" }] "
1818
1919 func test_decodeEvents( ) async throws {
20- let web3 = try ! await Web3 . new ( LocalTestCase . url)
21- let contract = web3. contract ( EthereumContractTest . eventsOnlyABI) !
20+ let web3 = try await Web3 . new ( LocalTestCase . url)
21+ let contract = try XCTUnwrap ( web3. contract ( EthereumContractTest . eventsOnlyABI) )
2222
2323 XCTAssertTrue ( contract. contract. allEvents. count == 6 )
2424 XCTAssertNotNil ( contract. contract. events [ " ContractCreated " ] )
@@ -30,8 +30,8 @@ class EthereumContractTest: LocalTestCase {
3030 }
3131
3232 func test_decodedAllFunctions( ) async throws {
33- let web3 = try ! await Web3 . new ( LocalTestCase . url)
34- let contract = web3. contract ( EthereumContractTest . overloadedFunctionsABI) !
33+ let web3 = try await Web3 . new ( LocalTestCase . url)
34+ let contract = try XCTUnwrap ( web3. contract ( EthereumContractTest . overloadedFunctionsABI) )
3535
3636 XCTAssertTrue ( contract. contract. allMethods. count == 5 )
3737
@@ -53,8 +53,8 @@ class EthereumContractTest: LocalTestCase {
5353 }
5454
5555 func test_encodeMethodBasedOnNameWithParameters_mustFail( ) async throws {
56- let web3 = try ! await Web3 . new ( LocalTestCase . url)
57- let contract = web3. contract ( EthereumContractTest . overloadedFunctionsABI) !
56+ let web3 = try await Web3 . new ( LocalTestCase . url)
57+ let contract = try XCTUnwrap ( web3. contract ( EthereumContractTest . overloadedFunctionsABI) )
5858
5959 /// Encoding method that expects parameters but we are not giving any.
6060 /// Result must be `nil`.
@@ -63,43 +63,41 @@ class EthereumContractTest: LocalTestCase {
6363 }
6464
6565 func test_encodeMethodBasedOnNameWithParameters( ) async throws {
66- let web3 = try ! await Web3 . new ( LocalTestCase . url)
67- let contract = web3. contract ( EthereumContractTest . overloadedFunctionsABI,
68- at: EthereumAddress ( " 0x6394b37Cf80A7358b38068f0CA4760ad49983a1B " ) !) !
66+ let web3 = try await Web3 . new ( LocalTestCase . url)
67+ let contract = try XCTUnwrap ( web3. contract ( EthereumContractTest . overloadedFunctionsABI, at: EthereumAddress ( " 0x6394b37Cf80A7358b38068f0CA4760ad49983a1B " ) ) )
6968 let parameters : [ AnyObject ] = [
70- [ Data . randomBytes ( length: 32 ) !,
71- Data . randomBytes ( length: 32 ) !] ,
72- [ Data . randomBytes ( length: 32 ) !,
73- Data . randomBytes ( length: 32 ) !]
69+ [ Data . randomBytes ( length: 32 ) , Data . randomBytes ( length: 32 ) ] ,
70+ [ Data . randomBytes ( length: 32 ) , Data . randomBytes ( length: 32 ) ]
7471 ] as [ AnyObject ]
7572 let functionNameWithParameters = " setData(bytes32[],bytes[]) "
7673 let transaction = contract. createWriteOperation ( functionNameWithParameters, parameters: parameters)
7774 XCTAssertNotNil ( transaction)
7875
79- func testDecoding( _ method: String ) {
80- let decodedData = contract. contract. methods [ method] ? . first? . decodeInputData ( transaction!. transaction. data)
76+ func testDecoding( _ method: String ) throws {
77+ let data = try XCTUnwrap ( transaction? . transaction. data)
78+ let decodedData = try XCTUnwrap ( contract. contract. methods [ method] ? . first? . decodeInputData ( data) )
8179 XCTAssertNotNil ( decodedData)
82- XCTAssertEqual ( decodedData! [ " 0 " ] as! [ Data ] , parameters [ 0 ] as! [ Data ] )
83- XCTAssertEqual ( decodedData! [ " 1 " ] as! [ Data ] , parameters [ 1 ] as! [ Data ] )
80+ XCTAssertEqual ( try XCTUnwrap ( decodedData [ " 0 " ] as? [ Data ] ) , try XCTUnwrap ( parameters [ 0 ] as? [ Data ] ) )
81+ XCTAssertEqual ( try XCTUnwrap ( decodedData [ " 1 " ] as? [ Data ] ) , try XCTUnwrap ( parameters [ 1 ] as? [ Data ] ) )
8482 }
8583
86- testDecoding ( functionNameWithParameters)
87- testDecoding ( getFuncSignature ( functionNameWithParameters) )
84+ try testDecoding ( functionNameWithParameters)
85+ try testDecoding ( getFuncSignature ( functionNameWithParameters) )
8886 }
8987
9088 func test_encodeMethodBasedOnHexSignature( ) async throws {
91- let web3 = try ! await Web3 . new ( LocalTestCase . url)
92- let contract = web3. contract ( EthereumContractTest . overloadedFunctionsABI,
93- at: EthereumAddress ( " 0x6394b37Cf80A7358b38068f0CA4760ad49983a1B " ) !) !
94- let parameters : [ AnyObject ] = [ Data . randomBytes ( length: 32 ) !, Data . randomBytes ( length: 32 ) !] as [ AnyObject ]
89+ let web3 = try await Web3 . new ( LocalTestCase . url)
90+ let contract = try XCTUnwrap ( web3. contract ( EthereumContractTest . overloadedFunctionsABI, at: EthereumAddress ( " 0x6394b37Cf80A7358b38068f0CA4760ad49983a1B " ) ) )
91+ let parameters : [ AnyObject ] = [ Data . randomBytes ( length: 32 ) , Data . randomBytes ( length: 32 ) ] as [ AnyObject ]
9592 let functionSignature = getFuncSignature ( " setData(bytes32,bytes) " )
9693 let transaction = contract. createWriteOperation ( functionSignature, parameters: parameters)
9794 XCTAssertNotNil ( transaction)
9895
99- let decodedData = contract. contract. methods [ functionSignature] ? . first? . decodeInputData ( transaction!. transaction. data)
96+ let data = try XCTUnwrap ( transaction? . transaction. data)
97+ let decodedData = try XCTUnwrap ( contract. contract. methods [ functionSignature] ? . first? . decodeInputData ( data) )
10098 XCTAssertNotNil ( decodedData)
101- XCTAssertEqual ( decodedData! [ " 0 " ] as! Data , parameters [ 0 ] as! Data )
102- XCTAssertEqual ( decodedData! [ " 1 " ] as! Data , parameters [ 1 ] as! Data )
99+ XCTAssertEqual ( try XCTUnwrap ( decodedData [ " 0 " ] as? Data ) , try XCTUnwrap ( parameters [ 0 ] as? Data ) )
100+ XCTAssertEqual ( try XCTUnwrap ( decodedData [ " 1 " ] as? Data ) , try XCTUnwrap ( parameters [ 1 ] as? Data ) )
103101 }
104102}
105103
0 commit comments