-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix!: remove offset from decodeLog
and decodeFunctionResult
methods
#2308
Changes from 5 commits
99aa766
e5ccfa4
dbe1564
c71bd01
46cc00b
a6f1494
7799643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@fuel-ts/abi-coder": minor | ||
--- | ||
|
||
Changed decodeLog and decodeFunctionResult return types to have only decoded value without an offset | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> { | |
|
||
throw new FuelError( | ||
ErrorCode.FUNCTION_NOT_FOUND, | ||
`function ${nameOrSignatureOrSelector} not found: ${JSON.stringify(fn)}.` | ||
`Function ${nameOrSignatureOrSelector} not found.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
} | ||
|
||
|
@@ -71,11 +71,11 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> { | |
const fragment = | ||
typeof functionFragment === 'string' ? this.getFunction(functionFragment) : functionFragment; | ||
|
||
return fragment.decodeOutput(data); | ||
return fragment.decodeOutput(data)[0]; | ||
} | ||
|
||
decodeLog(data: BytesLike, logId: string): any { | ||
const loggedType = this.jsonAbi.loggedTypes.find((type) => type.logId === logId); | ||
const loggedType = this.jsonAbi.loggedTypes.find((type) => type.logId.toString() === logId); | ||
nedsalk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!loggedType) { | ||
throw new FuelError( | ||
ErrorCode.LOG_TYPE_NOT_FOUND, | ||
|
@@ -85,7 +85,7 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> { | |
|
||
return AbiCoder.decode(this.jsonAbi, loggedType.loggedType, arrayify(data), 0, { | ||
encoding: this.encoding, | ||
}); | ||
})[0]; | ||
} | ||
|
||
encodeConfigurable(name: string, value: InputValue) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -766,4 +766,42 @@ describe('Abi interface', () => { | |
); | ||
}); | ||
}); | ||
|
||
describe('decodeLog', () => { | ||
it('should return decoded log by id', () => { | ||
const data = exhaustiveExamplesInterface.decodeLog('0x01000000000000000000000000000020', '0'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Also, passing in |
||
expect(data).toEqual({ | ||
a: true, | ||
b: 32, | ||
nedsalk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); | ||
|
||
it('should throw an error when log does not exist', () => { | ||
expect(() => | ||
exhaustiveExamplesInterface.decodeLog('0x01000000000000000000000000000020', '1') | ||
).toThrowError(`Log type with logId '1' doesn't exist in the ABI.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use the |
||
}); | ||
}); | ||
|
||
describe('decodeFunctionResult', () => { | ||
it('should return decoded function result', () => { | ||
const data = exhaustiveExamplesInterface.decodeFunctionResult( | ||
'struct_simple', | ||
'0x01000000000000000000000000000020' | ||
); | ||
expect(data).toEqual({ | ||
a: true, | ||
b: 32, | ||
}); | ||
}); | ||
|
||
it('should throw an error when function does not exist', () => { | ||
expect(() => { | ||
exhaustiveExamplesInterface.decodeFunctionResult( | ||
'doesnt_exist', | ||
'0x01000000000000000000000000000020' | ||
); | ||
}).toThrowError(/^Function doesnt_exist not found\.$/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use the |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some CI logic that mandates that this text is equal to the pr title.