Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 14, 2024
1 parent 5cc207b commit 87351c6
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion test/unit/server/soroban/request_airdrop_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Account, Keypair, StrKey, Networks, xdr, hash } = StellarSdk;
const { Account, Keypair, StrKey, Networks, xdr, hash, nativeToScVal } = StellarSdk;
const { Server, AxiosClient } = StellarSdk.rpc;

describe("Server#requestAirdrop", function () {
Expand Down Expand Up @@ -253,4 +253,91 @@ describe("Server#requestAirdrop", function () {
done();
});
});

it("falls back to RPC if no meta is present", function (done) {
const friendbotUrl = "https://friendbot.stellar.org";
const accountId =
"GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";
mockGetNetwork.call(this, friendbotUrl);

this.axiosMock
.expects("post")
.withArgs(`${friendbotUrl}?addr=${accountId}`)
.returns(Promise.resolve({ data: { hash: "deadbeef" } }));

const txResult = makeTxResult("SUCCESS");
txResult.txHash = "deadbeef";
txResult.resultMetaXdr = transactionMetaFor(accountId, "1234").toXDR("base64");

this.axiosMock
.expects("post")
.withArgs(serverUrl, {
jsonrpc: "2.0",
id: 1,
method: "getTransaction",
params: {
"hash": "deadbeef"
},
})
.returns(Promise.resolve({ data: { result: txResult } }));

this.server
.requestAirdrop(accountId)
.then((response) => {
expect(response).to.be.deep.equal(new Account(accountId, "1234"));
done();
})
.catch((err) => done(err));
});
});

// ripped out of ./get_transaction_test.js
function makeTxResult(status, addSoroban = true) {
const metaV3 = new xdr.TransactionMeta(
3,
new xdr.TransactionMetaV3({
ext: new xdr.ExtensionPoint(0),
txChangesBefore: [],
operations: [],
txChangesAfter: [],
sorobanMeta: new xdr.SorobanTransactionMeta({
ext: new xdr.SorobanTransactionMetaExt(0),
events: [],
diagnosticEvents: [],
returnValue: nativeToScVal(1234),
}),
}),
);

// only injected in the success case
//
// this data was picked from a random transaction in horizon:
// aa6a8e198abe53c7e852e4870413b29fe9ef04da1415a97a5de1a4ae489e11e2
const successInfo = {
ledger: 1234,
createdAt: 123456789010,
applicationOrder: 2,
feeBump: false,
envelopeXdr:
"AAAAAgAAAAAT/LQZdYz0FcQ4Xwyg8IM17rkUx3pPCCWLu+SowQ/T+gBLB24poiQa9iwAngAAAAEAAAAAAAAAAAAAAABkwdeeAAAAAAAAAAEAAAABAAAAAC/9E8hDhnktyufVBS5tqA734Yz5XrLX2XNgBgH/YEkiAAAADQAAAAAAAAAAAAA1/gAAAAAv/RPIQ4Z5Lcrn1QUubagO9+GM+V6y19lzYAYB/2BJIgAAAAAAAAAAAAA1/gAAAAQAAAACU0lMVkVSAAAAAAAAAAAAAFDutWuu6S6UPJBrotNSgfmXa27M++63OT7TYn1qjgy+AAAAAVNHWAAAAAAAUO61a67pLpQ8kGui01KB+Zdrbsz77rc5PtNifWqODL4AAAACUEFMTEFESVVNAAAAAAAAAFDutWuu6S6UPJBrotNSgfmXa27M++63OT7TYn1qjgy+AAAAAlNJTFZFUgAAAAAAAAAAAABQ7rVrrukulDyQa6LTUoH5l2tuzPvutzk+02J9ao4MvgAAAAAAAAACwQ/T+gAAAEA+ztVEKWlqHXNnqy6FXJeHr7TltHzZE6YZm5yZfzPIfLaqpp+5cyKotVkj3d89uZCQNsKsZI48uoyERLne+VwL/2BJIgAAAEA7323gPSaezVSa7Vi0J4PqsnklDH1oHLqNBLwi5EWo5W7ohLGObRVQZ0K0+ufnm4hcm9J4Cuj64gEtpjq5j5cM",
resultXdr:
"AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAANAAAAAAAAAAUAAAACZ4W6fmN63uhVqYRcHET+D2NEtJvhCIYflFh9GqtY+AwAAAACU0lMVkVSAAAAAAAAAAAAAFDutWuu6S6UPJBrotNSgfmXa27M++63OT7TYn1qjgy+AAAYW0toL2gAAAAAAAAAAAAANf4AAAACcgyAkXD5kObNTeRYciLh7R6ES/zzKp0n+cIK3Y6TjBkAAAABU0dYAAAAAABQ7rVrrukulDyQa6LTUoH5l2tuzPvutzk+02J9ao4MvgAAGlGnIJrXAAAAAlNJTFZFUgAAAAAAAAAAAABQ7rVrrukulDyQa6LTUoH5l2tuzPvutzk+02J9ao4MvgAAGFtLaC9oAAAAApmc7UgUBInrDvij8HMSridx2n1w3I8TVEn4sLr1LSpmAAAAAlBBTExBRElVTQAAAAAAAABQ7rVrrukulDyQa6LTUoH5l2tuzPvutzk+02J9ao4MvgAAIUz88EqYAAAAAVNHWAAAAAAAUO61a67pLpQ8kGui01KB+Zdrbsz77rc5PtNifWqODL4AABpRpyCa1wAAAAKYUsaaCZ233xB1p+lG7YksShJWfrjsmItbokiR3ifa0gAAAAJTSUxWRVIAAAAAAAAAAAAAUO61a67pLpQ8kGui01KB+Zdrbsz77rc5PtNifWqODL4AABv52PPa5wAAAAJQQUxMQURJVU0AAAAAAAAAUO61a67pLpQ8kGui01KB+Zdrbsz77rc5PtNifWqODL4AACFM/PBKmAAAAAJnhbp+Y3re6FWphFwcRP4PY0S0m+EIhh+UWH0aq1j4DAAAAAAAAAAAAAA9pAAAAAJTSUxWRVIAAAAAAAAAAAAAUO61a67pLpQ8kGui01KB+Zdrbsz77rc5PtNifWqODL4AABv52PPa5wAAAAAv/RPIQ4Z5Lcrn1QUubagO9+GM+V6y19lzYAYB/2BJIgAAAAAAAAAAAAA9pAAAAAA=",
resultMetaXdr: metaV3.toXDR("base64"),
};

if (!addSoroban) {
// replace the V3 Soroban meta with a "classic" V2 version
successInfo.resultMetaXdr =
"AAAAAgAAAAIAAAADAtL5awAAAAAAAAAAS0CFMhOtWUKJWerx66zxkxORaiH6/3RUq7L8zspD5RoAAAAAAcm9QAKVkpMAAHpMAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAAC0vi5AAAAAGTB02oAAAAAAAAAAQL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AAAAAAAAAAAEAAABbBXKIigAAABhZWyiOAAAAAgAAAAAAAAAAAAAAAAAAAAMAAAAAAtL0awAAAABkwbqrAAAAAAAAAAEC0vlrAAAAAAAAAABuHMLu9cxzV8d4xws0RjiLYXJ38EYHzdn/wKBxSyzHJQAAAB9+/s10Al3UUwAAEmQAAAKSAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAABAAAAWwVyiIoAAAAYWVsojgAAAAIAAAAAAAAAAAAAAAAAAAADAAAAAALS9GsAAAAAZMG6qwAAAAAAAAAA";
}

return {
status,
txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8",
latestLedger: 100,
latestLedgerCloseTime: 12345,
oldestLedger: 50,
oldestLedgerCloseTime: 500,
...(status === "SUCCESS" && successInfo),
};
}

0 comments on commit 87351c6

Please sign in to comment.