fix: make transaction-generating scripts more robust (#2690)

* improve scripts

* Update settings.json

* update file locations after refactor
This commit is contained in:
Mayukha Vadari
2024-10-11 14:40:19 -07:00
committed by GitHub
parent 649bf7d277
commit 8beb1292b5
2 changed files with 13 additions and 14 deletions

View File

@@ -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
@@ -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*/'
}
}
@@ -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*/'
}
}

View File

@@ -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,
@@ -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,
@@ -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())
@@ -248,10 +248,11 @@ ${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)
@@ -259,9 +260,7 @@ ${validationImportLine}`
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) {