Skip to content

Commit

Permalink
feat: Add Turkey forex (#260)
Browse files Browse the repository at this point in the history
- Add Turkey forex
- Update testing documentation
- Fixes CI issue due to breaking `dfx` change
  • Loading branch information
nategurian authored Mar 4, 2024
1 parent 97d6731 commit 2992c1e
Show file tree
Hide file tree
Showing 12 changed files with 688 additions and 168 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,18 @@ jobs:
rustup default ${{ matrix.rust }}
rustup target add wasm32-unknown-unknown
- name: Install DFX
env:
DFXVM_INIT_YES: true
run: |
wget --output-document install-dfx.sh "https://internetcomputer.org/install.sh"
bash install-dfx.sh < <(yes Y)
wget --output-document install-dfx.sh "https://sdk.dfinity.org/install.sh"
bash install-dfx.sh
rm install-dfx.sh
source "$HOME/.local/share/dfx/env"
dfx cache install
echo "$HOME/bin" >> $GITHUB_PATH
- name: Run e2e tests
run: |
source "$HOME/.local/share/dfx/env"
./scripts/e2e-tests
# Lints all of the shell scripts.
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ RUN mkdir -p src/xrc-tests/src && \

# Install dfx
COPY dfx.json dfx.json
RUN DFX_VERSION="$(jq -cr .dfx dfx.json)" sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"

ENV PATH="/root/.local/share/dfx/bin:${PATH}"
RUN DFXVM_INIT_YES=true DFX_VERSION="$(jq -cr .dfx dfx.json)" sh -c "$(curl -fsSL https://sdk.dfinity.org/install.sh)" && dfx --version

# Start the second container
FROM builder AS build
Expand Down
4 changes: 3 additions & 1 deletion src/xrc-tests/docker/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ RUN apt-get update && apt-get install -y \
WORKDIR /work
ADD /src/xrc/xrc.did /work/src/xrc/xrc.did
ADD /dfx.json /work/dfx.json
RUN DFX_VERSION="$(jq -cr .dfx dfx.json)" sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"

ENV PATH="/root/.local/share/dfx/bin:${PATH}"
RUN DFXVM_INIT_YES=true DFX_VERSION="$(jq -cr .dfx dfx.json)" sh -c "$(curl -fsSL https://sdk.dfinity.org/install.sh)" && dfx --version
# Make a default identity
RUN dfx identity get-principal

Expand Down
4 changes: 4 additions & 0 deletions src/xrc-tests/src/mock_responses/forex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod italy;
mod myanmar;
mod nepal;
mod switzerland;
mod turkey;
mod uzbekistan;

pub fn build_common_responses(
Expand Down Expand Up @@ -63,6 +64,9 @@ where
Forex::SwissFederalOfficeForCustoms(_) => {
switzerland::build_response_body(yesterday_timestamp, rates)
}
Forex::CentralBankOfTurkey(_) => {
turkey::build_response_body(yesterday_timestamp, rates)
}
})
.unwrap_or_default();
ExchangeResponse::builder()
Expand Down
101 changes: 101 additions & 0 deletions src/xrc-tests/src/mock_responses/forex/turkey.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use std::collections::HashMap;

use crate::container::ResponseBody;

const TEMPLATE: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="isokur.xsl"?>
<Tarih_Date Tarih="[DATE_STRING]" Date="01/31/2024" Bulten_No="2024/22" >
<Currency CrossOrder="0" Kod="USD" CurrencyCode="USD">
<Unit>1</Unit>
<Isim>ABD DOLARI</Isim>
<CurrencyName>US DOLLAR</CurrencyName>
<ForexBuying>[USD_BUY]</ForexBuying>
<ForexSelling>[USD_SELL]</ForexSelling>
<BanknoteBuying>30.2740</BanknoteBuying>
<BanknoteSelling>30.3953</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="1" Kod="AUD" CurrencyCode="AUD">
<Unit>1</Unit>
<Isim>AVUSTRALYA DOLARI</Isim>
<CurrencyName>AUSTRALIAN DOLLAR</CurrencyName>
<ForexBuying>[AUD_BUY]</ForexBuying>
<ForexSelling>[AUD_SELL]</ForexSelling>
<BanknoteBuying>19.7866</BanknoteBuying>
<BanknoteSelling>20.1277</BanknoteSelling>
<CrossRateUSD>1.5205</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="16" Kod="CNY" CurrencyCode="CNY">
<Unit>1</Unit>
<Isim>ÇİN YUANI</Isim>
<CurrencyName>CHINESE RENMINBI</CurrencyName>
<ForexBuying>[CNY_BUY]</ForexBuying>
<ForexSelling>[CNY_SELL]</ForexSelling>
<BanknoteBuying></BanknoteBuying>
<BanknoteSelling></BanknoteSelling>
<CrossRateUSD>7.1788</CrossRateUSD>
<CrossRateOther/>
</Currency>
<Currency CrossOrder="9" Kod="EUR" CurrencyCode="EUR">
<Unit>1</Unit>
<Isim>EURO</Isim>
<CurrencyName>EURO</CurrencyName>
<ForexBuying>[EUR_BUY]</ForexBuying>
<ForexSelling>[EUR_SELL]</ForexSelling>
<BanknoteBuying>32.7655</BanknoteBuying>
<BanknoteSelling>32.8968</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther>1.0823</CrossRateOther>
</Currency>
<Currency CrossOrder="10" Kod="GBP" CurrencyCode="GBP">
<Unit>1</Unit>
<Isim>İNGİLİZ STERLİNİ</Isim>
<CurrencyName>POUND STERLING</CurrencyName>
<ForexBuying>[GBP_BUY]</ForexBuying>
<ForexSelling>[GBP_SELL]</ForexSelling>
<BanknoteBuying>38.3130</BanknoteBuying>
<BanknoteSelling>38.5975</BanknoteSelling>
<CrossRateUSD/>
<CrossRateOther>1.2677</CrossRateOther>
</Currency>
<Currency CrossOrder="5" Kod="JPY" CurrencyCode="JPY">
<Unit>100</Unit>
<Isim>JAPON YENİ</Isim>
<CurrencyName>JAPENESE YEN</CurrencyName>
<ForexBuying>[JPY_BUY]</ForexBuying>
<ForexSelling>[JPY_SELL]</ForexSelling>
<BanknoteBuying>20.3812</BanknoteBuying>
<BanknoteSelling>20.6706</BanknoteSelling>
<CrossRateUSD>147.74</CrossRateUSD>
<CrossRateOther/>
</Currency>
</Tarih_Date>
"#;

pub fn build_response_body(timestamp: u64, rates: HashMap<&str, &str>) -> ResponseBody {
let date = time::OffsetDateTime::from_unix_timestamp(timestamp as i64).expect(
"Failed to make date from given timestamp while build response for the Central Bank of Turkey.",
);
let format = time::format_description::parse("[day].[month].[year]")
.expect("Unable to determine time format for the Central Bank of Turkey.");
let date_string = date
.format(&format)
.expect("Failed to format date for the Central Bank of Turkey.");
let xml = TEMPLATE
.replace("[DATE_STRING]", &date_string)
.replace("[EUR_BUY]", rates.get("EUR").cloned().unwrap_or("32.7884"))
.replace("[EUR_SELL]", rates.get("EUR").cloned().unwrap_or("32.8475"))
.replace("[GBP_BUY]", rates.get("GBP").cloned().unwrap_or("38.3398"))
.replace("[GBP_SELL]", rates.get("GBP").cloned().unwrap_or("38.5397"))
.replace("[USD_BUY]", rates.get("USD").cloned().unwrap_or("30.2952"))
.replace("[USD_SELL]", rates.get("USD").cloned().unwrap_or("30.3497"))
.replace("[JPY_BUY]", rates.get("JPY").cloned().unwrap_or("20.4569"))
.replace("[JPY_SELL]", rates.get("JPY").cloned().unwrap_or("20.5924"))
.replace("[CNY_BUY]", rates.get("CNY").cloned().unwrap_or("4.3914"))
.replace("[CNY_SELL]", rates.get("CNY").cloned().unwrap_or("4.4129"))
.replace("[AUD_BUY]", rates.get("AUD").cloned().unwrap_or("19.8780"))
.replace("[AUD_SELL]", rates.get("AUD").cloned().unwrap_or("20.0076"));
ResponseBody::Xml(xml.as_bytes().to_vec())
}
Loading

0 comments on commit 2992c1e

Please sign in to comment.