-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
All system contract compatibility and better tests #52
Conversation
It was casting undefined to a string and never using `this.account`
This matches the syntax used in the CDT, as discussed here: https://github.com/orgs/wharfkit/discussions/5#discussioncomment-6515701
src/codegen/helpers.ts
Outdated
'UInt64', | ||
'UInt8', | ||
] | ||
const EOSIO_CORE_CLASSES: string[] = [] |
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 should probably rename this variable too 😄 Maybe to ANTELOPE_CLASSES
?
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.
Totally agreed, didn't even think about that 😂
@@ -68,3 +69,21 @@ export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration { | |||
ts.NodeFlags.Namespace | |||
) | |||
} | |||
|
|||
function findParamTypeString(typeString: string, namespace: string | null, abi: ABI.Def): string { |
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.
Is this method specific to interfaces? If not, I would put it in the helper.ts
file.
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.
I think it is exclusive to the interfaces, since it's only used for ActionParams
as it finds the loose types like NameType
or IntType
.
import * as ts from 'typescript' | ||
import {findAbiType} from './helpers' | ||
|
||
export function generateTableMap(abi: ABI.Def): ts.VariableStatement { | ||
// Map over tables to create the object properties | ||
const tableProperties = abi.tables.map((table) => | ||
ts.factory.createPropertyAssignment( | ||
String(table.name), | ||
JSON.stringify(table.name), |
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.
TIL 🤷
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.
Right? lol....
src/codegen/structs.ts
Outdated
return 'boolean' | ||
} | ||
|
||
if (['String', 'Boolean', 'Number'].includes(fieldType)) { |
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.
Nice catch, but if Boolean
isn't a thing then we should probably remove it from this line.
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.
I'm not sure if it is or isn't a thing, so I didn't want to remove it 😅
test/tests/generic.ts
Outdated
@@ -0,0 +1,77 @@ | |||
import {Action, Name} from '@wharfkit/antelope' |
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.
I wonder if we need a tests/helpers
folder for functions like these 🤔
}) | ||
const contract = await contractKit.load('eosio.token') | ||
const result = await contract.table('accounts', 'wharfkittest').get() | ||
assert.instanceOf(result.balance, Asset) |
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.
Does this test really make sure that the correct scope is used? 🤔 Wouldn't the balance field always return an Asset?
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.
I left you some comments, but this looks great! I think that we can go ahead and merge this whenever you're ready
@dafuga I didn't want to merge this yet. Instead I figured I'd just hand this branch off to you to work with, since the original comment on this PR still has a bunch of code generation stuff that needs to be addressed to fix the failing tests within. |
Sounds good! I'll make a new PR using this as a base branch and we can just merge them both at the same time. |
Codegen touchups
Alright… some updates!
I fixed the dot notation issue I mentioned with the eosio contract, which led to a bunch of other things - some of which I also managed to fix. But there’s more 😅
The dot notation thing was that in the system contract, there are tables with . in the name, which when passed in to the factory, was creating object properties with . in them, like powup.state: value and causing errors.
Fix was easy, using JSON.stringify(): f6cfcaf
I then went in and rewrote the tests to loop over and test against 4 contracts: eosio , eosio.token, eosio.msig and rewards.gm. All the testing data is setup to process these, but the tests are commented out preventing the failure. To enable them, uncomment here:
contract/test/tests/codegen.ts
Lines 7 to 10 in 6de4f4c
and here:
contract/test/tests/codegen.ts
Lines 25 to 32 in 6de4f4c
This is going to cause a number of errors that need to be fixed. There's a bunch of edge cases I don't think we noticed in our limited testing that these additional contracts are now showing. This includes:
abi.types
The "types" top level field of the ABI needs to be used to resolve mapping issues. These are "mappings" essentially between various types and the eosio contract uses them. At build time we need to read this data and link things properly. Here's the relevant part from the eosio contract abi and an example:
You can see
regproducer2
usingblock_signing_authority
. This isn't a struct, it's a top level type, that maps to a variant. Resolving this will lead to the appropriate type...This would mean that on the
regproducer2
action, we should map it like this:contract/test/data/contracts/mock-eosio.ts
Lines 1117 to 1127 in 6de4f4c
On the above link, notice how I already corrected the "mock" version of the code to be what's expected 👍
hoisting
Within the type declarations of the generated code we're going to need to somehow do hoisting.
If you generate the eosio contract, you'll notice that going in order from the ABI the generated code will throw errors. It's because some types are being used before they are defined, like with
ProducerKey
andProducerSchedule
. We need the output code to detect this and then order them so these errors don't occur.The abi2core library did this, and has a function which might solve this problem:
https://github.com/greymass/abi2core/blob/master/src/toposort.ts
missing types
Some types aren't resolving properly, you'll notice these if you run against the eosio and eosio.msig contracts. Things like
block_timestamp_type
orVaruint32
. In the "mock" versions of the contracts I fixed these, but the generator needs to have a mapping for these.If you simply run the tests you'll see them!
values ending with
$
Unsure what's going on, but there are lots of
$
at the end some values that aren't being removed. You'll see these again if you run the tests.