Skip to content

Commit

Permalink
fix: make transaction-generating scripts more robust (#2690)
Browse files Browse the repository at this point in the history
* improve scripts

* Update settings.json

* update file locations after refactor
  • Loading branch information
mvadari authored Oct 11, 2024
1 parent 649bf7d commit 8beb129
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/xrpl/tools/createValidateTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getTx(txName) {
.filter((tx) => tx.json.TransactionType === txName)
.map((tx) => tx.json)
if (validTxs.length == 0) {
throw new Error(`Must have ripple-binary-codec fixture for ${txName}`)
return '{ /* TODO: add sample transaction */ }'
}
const validTx = validTxs[0]
delete validTx.TxnSignature
Expand Down Expand Up @@ -74,7 +74,7 @@ function getInvalidValue(paramTypes) {
} else if (paramType == 'XChainBridge') {
return JSON.stringify({ XChainDoor: 'test' })
} else {
throw Error(`${paramType} not supported yet`)
return '/*TODO*/'
}
}

Expand All @@ -86,7 +86,7 @@ function getInvalidValue(paramTypes) {
} else if (JSON.stringify(simplifiedParamTypes) === '["number","string"]') {
return JSON.stringify({ currency: 'ETH' })
} else {
throw Error(`${simplifiedParamTypes} not supported yet`)
return '/*TODO*/'
}
}

Expand Down
21 changes: 10 additions & 11 deletions packages/xrpl/tools/generateModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let jsTransactionFile

function processRippledSource(folder) {
const sfieldCpp = readFile(
path.join(folder, 'src/ripple/protocol/impl/SField.cpp'),
path.join(folder, 'src/libxrpl/protocol/SField.cpp'),
)
const sfieldHits = sfieldCpp.match(
/^ *CONSTRUCT_[^\_]+_SFIELD *\( *[^,\n]*,[ \n]*"([^\"\n ]+)"[ \n]*,[ \n]*([^, \n]+)[ \n]*,[ \n]*([0-9]+)(,.*?(notSigning))?/gm,
Expand All @@ -29,7 +29,7 @@ function processRippledSource(folder) {
}

const txFormatsCpp = readFile(
path.join(folder, 'src/ripple/protocol/impl/TxFormats.cpp'),
path.join(folder, 'src/libxrpl/protocol/TxFormats.cpp'),
)
const txFormatsHits = txFormatsCpp.match(
/^ *add\(jss::([^\"\n, ]+),[ \n]*tt[A-Z_]+,[ \n]*{[ \n]*(({sf[A-Za-z0-9]+, soe(OPTIONAL|REQUIRED|DEFAULT)},[ \n]+)*)},[ \n]*[pseudocC]+ommonFields\);/gm,
Expand All @@ -49,10 +49,10 @@ function processRippledSource(folder) {
),
)
const transactionMatch = jsTransactionFile.match(
/export type Transaction =([| \nA-Za-z]+)\nexport/,
/export type SubmittableTransaction =([| \nA-Za-z]+)\n\/\*\*/,
)[0]
const existingLibraryTxs = transactionMatch
.replace('\n\nexport', '')
.replace('\n\n/**', '')
.split('\n | ')
.filter((value) => !value.includes('export type'))
.map((value) => value.trim())
Expand Down Expand Up @@ -248,20 +248,19 @@ ${validationImportLine}`
)

const validateTests = createValidateTests(tx)
fs.writeFileSync(
path.join(path.dirname(__filename), `../test/models/${tx}.test.ts`),
validateTests,
)
if (validateTests !== '')
fs.writeFileSync(
path.join(path.dirname(__filename), `../test/models/${tx}.test.ts`),
validateTests,
)

updateTransactionFile(transactionMatch, tx)

updateIndexFile(tx)

console.log(`Added ${tx}`)
})
console.log(
'Future steps: Adding docstrings to the models and adding integration tests',
)
// TODO: add docstrings to the models and add integration tests
}

if (require.main === module) {
Expand Down

0 comments on commit 8beb129

Please sign in to comment.