XRPL API changes 4.0.0

This commit is contained in:
nitowa
2024-10-11 18:37:37 +02:00
parent dc322788c7
commit d84684aa84
6 changed files with 1039 additions and 727 deletions
+30 -18
View File
@@ -27,9 +27,25 @@ let owner_datawriter: Datawriter
const setup = async () => {
[ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(), makeTestnetWallet(), makeTestnetWallet(), makeTestnetWallet()])
// [ownerWallet, listeningWallet, userWallet, drainWallet] = await Promise.all([makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet(),makeTestnetWallet()])
[ownerWallet, listeningWallet, userWallet, drainWallet] = [
{
secret: 'sEd7tPDHFk3w7ABSaCPYi12iwucMQLt',
address: 'rDML7QhJeVxZTwsjPtm4iyLUJTCzzuppMo'
},
{
secret: 'sEdSgbyouvLM26vq2F2XthfKGWndP72',
address: 'rPvwbb4JHncG9rKVrYATJw6HRixR69wgjg'
},
{
secret: 'sEd7c1Y8JwWyA2owbchMWnuzAhB3ypY',
address: 'rwuuWdyxwf3o78Ce2DAZrYCQ12SSawTp6M'
},
{
secret: 'sEdScantwGA5gYe4atKPbG5bsriURpf',
address: 'rDiwSioTRyV29rNk2FskxqFtMaRsmWvS7C'
}
]
owner_datawriter = new Datawriter({
receiveAddress: drainWallet.address,
sendWallet: ownerWallet,
@@ -129,7 +145,7 @@ const setup = async () => {
describe('RJSVM basic functions', () => {
before(async function () {
this.timeout(10000)
this.timeout(100000)
await setup()
})
@@ -138,13 +154,15 @@ describe('RJSVM basic functions', () => {
})
it('Env contains the payload carrying transaction', function (done) {
this.timeout(30000)
this.timeout(45000)
console.log("Making wallet...")
makeTestnetWallet().then(async testWallet => {
console.log(testWallet)
//create a mock RJSVM
abstract class RJSVM_Base
extends RJSVM<undefined, { testEndpoint: () => void }>
implements RJSVM_Interface<RJSVM_Base> {
extends RJSVM<undefined, { testEndpoint: () => void }>
implements RJSVM_Interface<RJSVM_Base> {
owner = ownerWallet.address
state = undefined
}
@@ -153,17 +171,12 @@ describe('RJSVM basic functions', () => {
const RJSVM_Contract: RJSVM_Implementations<RJSVM_Base> = {
testEndpoint: {
implementation: function (env) {
expect(env.Account).to.be.equal(userWallet.address)
expect(env.Amount).to.be.equal('1')
expect(env.Destination).to.be.equal(testWallet.address)
expect(Number(env.Fee)).to.be.greaterThanOrEqual(10)
expect(env.LastLedgerSequence).to.be.a('number')
expect(env.Memos).to.be.an('Array')
const memo = JSON.parse(DataParser.hex_to_ascii(env.Memos[0].Memo.MemoData))
expect(memo.endpoint).to.be.equal('testEndpoint')
expect(env.Sequence).to.be.a('number')
expect(env.SigningPubKey).to.be.a('string')
expect(env.TransactionType).to.be.equal('Payment')
@@ -172,7 +185,6 @@ describe('RJSVM basic functions', () => {
expect(env.hash).to.be.a('string')
expect(env.inLedger).to.be.a('number')
expect(env.ledger_index).to.be.a('number')
runnable.disconnect()
done()
},
@@ -182,7 +194,7 @@ describe('RJSVM basic functions', () => {
}
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract)
const runnable = new Rjsvm({listeningAddress: testWallet.address,rippleNode: xrpNode})
const runnable = new Rjsvm({ listeningAddress: testWallet.address, rippleNode: xrpNode })
await runnable.connect()
const dw = new Datawriter({
@@ -197,7 +209,7 @@ describe('RJSVM basic functions', () => {
})
it('Called endpoint triggers in RJSVM', function (done) {
this.timeout(30000)
this.timeout(45000)
const data = { title: "1", body: "2", from: "3" };
rjsvm.once('submit', (payload) => {
@@ -209,7 +221,7 @@ describe('RJSVM basic functions', () => {
})
it('Calling an endpoint with insufficient fee fails', function (done) {
this.timeout(30000)
this.timeout(45000)
const data = { title: "f", body: "f", from: "f" };
rjsvm.once('error', (err) => {
@@ -220,7 +232,7 @@ describe('RJSVM basic functions', () => {
})
it('Restricted endpoint can be called by owner', function (done) {
this.timeout(30000)
this.timeout(45000)
const data = { title: "11", body: "22", from: "33" };
rjsvm.once('restricted', (payload) => {
@@ -233,7 +245,7 @@ describe('RJSVM basic functions', () => {
it('Restricted endpoint cannot be called by non-owner', function (done) {
this.timeout(30000)
this.timeout(45000)
const data = { title: "e", body: "e", from: "e" };
rjsvm.once('error', (err) => {
+14 -14
View File
@@ -1,16 +1,16 @@
import axios from 'axios';
type Wallet = {secret: string, address:string }
export const makeTestnetWallet = () : Promise<Wallet> => fetch('https://faucet.altnet.rippletest.net/accounts', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).then((raw:any) => {
return raw.json().then(content => {
return({
secret: content.account.secret,
address: content.account.address
});
})
});
export const makeTestnetWallet = async () : Promise<Wallet> => {
try{
const response = await axios.post('https://faucet.altnet.rippletest.net/accounts', {})
return ({
secret: response.data.seed,
address: response.data.account.address
})
}catch(e){
console.log(e)
}
}