Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit 8ab1f12

Browse files
committed
#102 - fixed incorrect encoding for dynamic collection, fixed relevant unit tests, added integration tests with deployment of simple getter contract with dynamic collection dependency
1 parent 12cff4c commit 8ab1f12

File tree

4 files changed

+123
-5
lines changed

4 files changed

+123
-5
lines changed

Example/Tests/ABI/EncodedABIFunctionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ final class EncodedABIFunctionTests: XCTestCase {
6161
hex: "cdcd77c0" +
6262
"0000000000000000000000000000000000000000000000000000000000000020" +
6363
"0000000000000000000000000000000000000000000000000000000000000002" +
64+
"0000000000000000000000000000000000000000000000000000000000000040" +
6465
"0000000000000000000000000000000000000000000000000000000000000080" +
65-
"00000000000000000000000000000000000000000000000000000000000000c0" +
6666
"0000000000000000000000000000000000000000000000000000000000000001" +
6767
"000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c5" +
6868
"0000000000000000000000000000000000000000000000000000000000000001" +
@@ -120,8 +120,8 @@ final class EncodedABIFunctionTests: XCTestCase {
120120
hex: "cdcd77c0" +
121121
"0000000000000000000000000000000000000000000000000000000000000020" +
122122
"0000000000000000000000000000000000000000000000000000000000000002" +
123-
"0000000000000000000000000000000000000000000000000000000000000080" +
124-
"00000000000000000000000000000000000000000000000000000000000000e0" +
123+
"0000000000000000000000000000000000000000000000000000000000000040" +
124+
"00000000000000000000000000000000000000000000000000000000000000a0" +
125125
"0000000000000000000000000000000000000000000000000000000000000002" +
126126
"000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100cf" +
127127
"000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c2" +

Example/Tests/ABI/EncodedABITupleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ final class EncodedABITupleTests: XCTestCase {
5353
Data(
5454
hex: "0000000000000000000000000000000000000000000000000000000000000020" +
5555
"0000000000000000000000000000000000000000000000000000000000000002" +
56+
"0000000000000000000000000000000000000000000000000000000000000040" +
5657
"0000000000000000000000000000000000000000000000000000000000000080" +
57-
"00000000000000000000000000000000000000000000000000000000000000c0" +
5858
"0000000000000000000000000000000000000000000000000000000000000001" +
5959
"000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c5" +
6060
"0000000000000000000000000000000000000000000000000000000000000001" +

Example/Tests/TransactionBytes/ContractDeploymentAndCallIT.swift

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,124 @@ final class ContractDeploymentAndCallIT: XCTestCase {
183183
)
184184
] as [ABIEncodedParameter]
185185
),
186+
(
187+
contractCode: BytesFromHexString(
188+
hex: "60806040523480156200001157600080fd5b5060405162000992380380620009928339810180604052620000379190810190620002b6565b80600090805190602001906200004f92919062000057565b505062000385565b828054828255906000526020600020908101928215620000ab579160200282015b82811115620000aa57825182908051906020019062000099929190620000be565b509160200191906001019062000078565b5b509050620000ba919062000116565b5090565b82805482825590600052602060002090810192821562000103579160200282015b8281111562000102578251829060001916905591602001919060010190620000df565b5b50905062000112919062000147565b5090565b6200014491905b808211156200014057600081816200013691906200016f565b506001016200011d565b5090565b90565b6200016c91905b80821115620001685760008160009055506001016200014e565b5090565b90565b50805460008255906000526020600020908101906200018f919062000147565b50565b600082601f8301121515620001a657600080fd5b8151620001bd620001b78262000329565b620002fb565b9150818183526020840193506020810190508360005b83811015620002075781518601620001ec888262000211565b845260208401935060208301925050600181019050620001d3565b5050505092915050565b600082601f83011215156200022557600080fd5b81516200023c620002368262000352565b620002fb565b915081818352602084019350602081019050838560208402820111156200026257600080fd5b60005b838110156200029657816200027b8882620002a0565b84526020840193506020830192505060018101905062000265565b5050505092915050565b6000620002ae82516200037b565b905092915050565b600060208284031215620002c957600080fd5b600082015167ffffffffffffffff811115620002e457600080fd5b620002f28482850162000192565b91505092915050565b6000604051905081810181811067ffffffffffffffff821117156200031f57600080fd5b8060405250919050565b600067ffffffffffffffff8211156200034157600080fd5b602082029050602081019050919050565b600067ffffffffffffffff8211156200036a57600080fd5b602082029050602081019050919050565b6000819050919050565b6105fd80620003956000396000f30060806040526004361061006c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062dad317146100715780632424ebe71461009c57806373d4a13a146100d957806381fda31614610104578063da33465514610141575b600080fd5b34801561007d57600080fd5b5061008661017e565b604051610093919061051b565b60405180910390f35b3480156100a857600080fd5b506100c360048036036100be9190810190610315565b61018a565b6040516100d0919061051b565b60405180910390f35b3480156100e557600080fd5b506100ee6101af565b6040516100fb91906104bc565b60405180910390f35b34801561011057600080fd5b5061012b6004803603610126919081019061033e565b610252565b6040516101389190610500565b60405180910390f35b34801561014d57600080fd5b5061016860048036036101639190810190610315565b61028c565b60405161017591906104de565b60405180910390f35b60008080549050905090565b6000808281548110151561019a57fe5b90600052602060002001805490509050919050565b60606000805480602002602001604051908101604052809291908181526020016000905b828210156102495783829060005260206000200180548060200260200160405190810160405280929190818152602001828054801561023557602002820191906000526020600020905b8154600019168152602001906001019080831161021d575b5050505050815260200190600101906101d3565b50505050905090565b6000808381548110151561026257fe5b906000526020600020018281548110151561027957fe5b9060005260206000200154905092915050565b606060008281548110151561029d57fe5b906000526020600020018054806020026020016040519081016040528092919081815260200182805480156102f557602002820191906000526020600020905b815460001916815260200190600101908083116102dd575b50505050509050919050565b600061030d82356105b9565b905092915050565b60006020828403121561032757600080fd5b600061033584828501610301565b91505092915050565b6000806040838503121561035157600080fd5b600061035f85828601610301565b925050602061037085828601610301565b9150509250929050565b60006103858261055d565b8084526020840193508360208202850161039e85610536565b60005b848110156103d75783830388526103b9838351610443565b92506103c48261057e565b91506020880197506001810190506103a1565b508196508694505050505092915050565b60006103f382610573565b80845260208401935061040583610550565b60005b828110156104375761041b86835161049e565b61042482610598565b9150602086019550600181019050610408565b50849250505092915050565b600061044e82610568565b80845260208401935061046083610543565b60005b828110156104925761047686835161049e565b61047f8261058b565b9150602086019550600181019050610463565b50849250505092915050565b6104a7816105a5565b82525050565b6104b6816105af565b82525050565b600060208201905081810360008301526104d6818461037a565b905092915050565b600060208201905081810360008301526104f881846103e8565b905092915050565b6000602082019050610515600083018461049e565b92915050565b600060208201905061053060008301846104ad565b92915050565b6000602082019050919050565b6000602082019050919050565b6000602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b6000602082019050919050565b6000602082019050919050565b6000819050919050565b6000819050919050565b60008190509190505600a265627a7a72305820e4eba7dab74878c23493b48feb97733749dbd3d9a238fbdaee586052f5ab435d6c6578706572696d656e74616cf50037"
189+
),
190+
arguments: [
191+
ABIDynamicCollection(
192+
parameters: [
193+
ABIDynamicCollection(
194+
parameters: [
195+
ABIFixedBytes(
196+
origin: BytesFromHexString(
197+
hex: "12"
198+
)
199+
),
200+
ABIFixedBytes(
201+
origin: BytesFromHexString(
202+
hex: "34"
203+
)
204+
)
205+
]
206+
),
207+
ABIDynamicCollection(
208+
parameters: [
209+
ABIFixedBytes(
210+
origin: BytesFromHexString(
211+
hex: "78"
212+
)
213+
),
214+
ABIFixedBytes(
215+
origin: BytesFromHexString(
216+
hex: "12"
217+
)
218+
),
219+
ABIFixedBytes(
220+
origin: BytesFromHexString(
221+
hex: "42"
222+
)
223+
)
224+
]
225+
)
226+
]
227+
)
228+
] as [ABIEncodedParameter]
229+
),
230+
(
231+
contractCode: BytesFromHexString(
232+
hex: "608060405234801561001057600080fd5b50604051610783380380610783833981018060405261003291908101906102ca565b8260009080519060200190610048929190610082565b5081600160006101000a81548160ff0219169083151502179055508060029080519060200190610079929190610082565b505050506103dc565b8280548282559060005260206000209081019282156100d1579160200282015b828111156100d05782518290805190602001906100c09291906100e2565b50916020019190600101906100a2565b5b5090506100de9190610135565b5090565b828054828255906000526020600020908101928215610124579160200282015b82811115610123578251829060001916905591602001919060010190610102565b5b5090506101319190610161565b5090565b61015e91905b8082111561015a57600081816101519190610186565b5060010161013b565b5090565b90565b61018391905b8082111561017f576000816000905550600101610167565b5090565b90565b50805460008255906000526020600020908101906101a49190610161565b50565b600082601f83011215156101ba57600080fd5b81516101cd6101c882610376565b610349565b9150818183526020840193506020810190508360005b8381101561021357815186016101f9888261021d565b8452602084019350602083019250506001810190506101e3565b5050505092915050565b600082601f830112151561023057600080fd5b815161024361023e8261039e565b610349565b9150818183526020840193506020810190508385602084028201111561026857600080fd5b60005b83811015610298578161027e88826102b6565b84526020840193506020830192505060018101905061026b565b5050505092915050565b60006102ae82516103c6565b905092915050565b60006102c282516103d2565b905092915050565b6000806000606084860312156102df57600080fd5b600084015167ffffffffffffffff8111156102f957600080fd5b610305868287016101a7565b9350506020610316868287016102a2565b925050604084015167ffffffffffffffff81111561033357600080fd5b61033f868287016101a7565b9150509250925092565b6000604051905081810181811067ffffffffffffffff8211171561036c57600080fd5b8060405250919050565b600067ffffffffffffffff82111561038d57600080fd5b602082029050602081019050919050565b600067ffffffffffffffff8211156103b557600080fd5b602082029050602081019050919050565b60008115159050919050565b6000819050919050565b610398806103eb6000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806373d4a13a14610046575b600080fd5b34801561005257600080fd5b5061005b610073565b60405161006a939291906102b9565b60405180910390f35b6060600060606000600160009054906101000a900460ff16600282805480602002602001604051908101604052809291908181526020016000905b828210156101245783829060005260206000200180548060200260200160405190810160405280929190818152602001828054801561011057602002820191906000526020600020905b815460001916815260200190600101908083116100f8575b5050505050815260200190600101906100ae565b50505050925080805480602002602001604051908101604052809291908181526020016000905b828210156101c1578382906000526020600020018054806020026020016040519081016040528092919081815260200182805480156101ad57602002820191906000526020600020905b81546000191681526020019060010190808311610195575b50505050508152602001906001019061014b565b505050509050925092509250909192565b60006101dd82610318565b808452602084019350836020820285016101f6856102fe565b60005b8481101561022f578383038852610211838351610240565b925061021c8261032e565b91506020880197506001810190506101f9565b508196508694505050505092915050565b600061024b82610323565b80845260208401935061025d8361030b565b60005b8281101561028f576102738683516102aa565b61027c8261033b565b9150602086019550600181019050610260565b50849250505092915050565b6102a481610348565b82525050565b6102b381610354565b82525050565b600060608201905081810360008301526102d381866101d2565b90506102e2602083018561029b565b81810360408301526102f481846101d2565b9050949350505050565b6000602082019050919050565b6000602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b6000602082019050919050565b60008115159050919050565b60008190509190505600a265627a7a723058209f1a8be541c2b54a130159307f3914aca907c30afd47a917a83ab4d6abadadf56c6578706572696d656e74616cf50037"
233+
),
234+
arguments: [
235+
ABIDynamicCollection(
236+
parameters: [
237+
ABIDynamicCollection(
238+
parameters: [
239+
ABIFixedBytes(
240+
origin: BytesFromHexString(
241+
hex: "12"
242+
)
243+
),
244+
ABIFixedBytes(
245+
origin: BytesFromHexString(
246+
hex: "34"
247+
)
248+
)
249+
]
250+
),
251+
ABIDynamicCollection(
252+
parameters: [
253+
ABIFixedBytes(
254+
origin: BytesFromHexString(
255+
hex: "78"
256+
)
257+
),
258+
ABIFixedBytes(
259+
origin: BytesFromHexString(
260+
hex: "12"
261+
)
262+
),
263+
ABIFixedBytes(
264+
origin: BytesFromHexString(
265+
hex: "42"
266+
)
267+
)
268+
]
269+
)
270+
]
271+
),
272+
ABIBoolean(
273+
origin: true
274+
),
275+
ABIDynamicCollection(
276+
parameters: [
277+
ABIDynamicCollection(
278+
parameters: [
279+
ABIFixedBytes(
280+
origin: BytesFromHexString(
281+
hex: "34"
282+
)
283+
)
284+
]
285+
),
286+
ABIDynamicCollection(
287+
parameters: [
288+
ABIFixedBytes(
289+
origin: BytesFromHexString(
290+
hex: "78"
291+
)
292+
),
293+
ABIFixedBytes(
294+
origin: BytesFromHexString(
295+
hex: "42"
296+
)
297+
)
298+
]
299+
)
300+
]
301+
),
302+
] as [ABIEncodedParameter]
303+
)
186304
]
187305
).forEach{ contractCode, arguments in
188306
expect{

Web3Swift/ABI/Parameters/ABIDynamicCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public final class ABIDynamicCollection: ABIEncodedParameter {
7272
] + ABITuple(
7373
parameters: parameters
7474
).heads(
75-
offset: offset + 1
75+
offset: 0
7676
)
7777
}
7878

0 commit comments

Comments
 (0)