Skip to content

Commit

Permalink
ci: add ci config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jecket1 committed May 13, 2024
1 parent a336dca commit 01f1ca4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 256 deletions.
29 changes: 13 additions & 16 deletions .github/workflows/test-with-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@ env:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
permissions:
pull-requests: write
contents: write
services:
elasticsearch:
image: elasticsearch:8.13.0
ports:
- 9200:9200
options: -e="discovery.type=single-node" -e="xpack.security.enabled=false" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0'
#- name: Verify Elasticsearch connection
# env:
# ELASTIC_SEARCH_URL: http://127.0.0.1:${{ job.services.elasticsearch.ports[9200] }}
# run: |
# echo $ELASTIC_SEARCH_URL
# curl -fsSL "$ELASTIC_SEARCH_URL/_cat/health?h=status"
dotnet-version: '6.0'

- name: 'Download AElf build tools'
run: bash scripts/download_binary.sh

- name: 'Install protobuf'
run: bash scripts/install.sh

- name: Install dependencies
run: dotnet restore --verbosity quiet

Expand All @@ -41,9 +36,11 @@ jobs:

- name: Test
run: |
for name in `ls ./test/*.Tests/*.csproj | awk '{print $NF}'`;
for name in $(ls ./test/*.Tests/*.csproj | awk '{print $NF}')
do
dotnet test ${name} --no-restore --no-build --logger trx --settings CodeCoverage.runsettings --results-directory coverage --collect:"XPlat Code Coverage"
echo "Running tests for $name..."
dotnet test $name --no-restore --no-build --logger trx --settings CodeCoverage.runsettings --results-directory coverage --collect:"XPlat Code Coverage" --verbosity normal
echo "Finished running tests for $name."
done
- name: Upload coverage reports to Codecov
Expand Down
3 changes: 2 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="aelf" value="https://www.myget.org/F/aelf-project-dev/api/v3/index.json" protocolVersion="3"/>
<add key="aelf" value="https://www.myget.org/F/aelf-project-dev/api/v3/index.json"/>
</packageSources>
</configuration>
239 changes: 0 additions & 239 deletions test/Forest.Tests/ForestContractTests_MakeOffer_whiteUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,247 +1892,8 @@ public async void MakeOffer_Case46_Allowance()
#endregion

}

//buy: elf allowance greatter enough
[Fact]
public async void Buy_Case47_Allowance()
{
await InitializeForestContract();
await PrepareNftData();

var sellPrice = Elf(1000_0000_0000);
var whitePrice = Elf(1_0000_0000);

#region ListWithFixedPrice

{
await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = whitePrice.Symbol, Amount = 5 });

await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput()
{
Symbol = NftSymbol,
Quantity = 5,
IsWhitelistAvailable = true,
Price = sellPrice,
Whitelists = new WhitelistInfoList()
{
Whitelists =
{
new WhitelistInfo()
{
PriceTag = new PriceTagInfo()
{
TagName = "WHITELIST_TAG",
Price = whitePrice
},
AddressList = new AddressList()
{
Value = { User2Address, User3Address },
}
},
// other WhitelistInfo here
// new WhitelistInfo() {}
}
},
Duration = new ListWithFixedPriceDuration()
{
// start 5min ago
StartTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
// public 10min after
PublicTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
DurationMinutes = 1 * 60,
},
});
}

#endregion

#region user2 make offer to user1
{
await User2TokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = whitePrice.Symbol, Amount = sellPrice.Amount*2+1 });
var executionResult = await BuyerForestContractStub.MakeOffer.SendAsync(new MakeOfferInput()
{
Symbol = NftSymbol,
OfferTo = User1Address,
Quantity = 2,
Price = sellPrice,
ExpireTime = Timestamp.FromDateTime(DateTime.UtcNow.AddMinutes(30))
});
}

#endregion
var nftBalance = await User2TokenContractStub.GetBalance.SendAsync(new GetBalanceInput()
{
Symbol = NftSymbol,
Owner = User2Address
});
nftBalance.Output.Balance.ShouldBe(2);
}


//buy: elf allowance equal enough
[Fact]
public async void Buy_Case48_Allowance()
{
await InitializeForestContract();
await PrepareNftData();

var sellPrice = Elf(1000_0000_0000);
var whitePrice = Elf(1_0000_0000);

#region ListWithFixedPrice

{
await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = 5 });

await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput()
{
Symbol = NftSymbol,
Quantity = 5,
IsWhitelistAvailable = true,
Price = sellPrice,
Whitelists = new WhitelistInfoList()
{
Whitelists =
{
new WhitelistInfo()
{
PriceTag = new PriceTagInfo()
{
TagName = "WHITELIST_TAG",
Price = whitePrice
},
AddressList = new AddressList()
{
Value = { User2Address, User3Address },
}
},
// other WhitelistInfo here
// new WhitelistInfo() {}
}
},
Duration = new ListWithFixedPriceDuration()
{
// start 5min ago
StartTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
// public 10min after
PublicTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
DurationMinutes = 1 * 60,
},
});
}

#endregion

#region user2 make offer to user1
{
await User2TokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = whitePrice.Symbol, Amount = sellPrice.Amount*2 });
var executionResult = await BuyerForestContractStub.MakeOffer.SendAsync(new MakeOfferInput()
{
Symbol = NftSymbol,
OfferTo = User1Address,
Quantity = 2,
Price = sellPrice,
ExpireTime = Timestamp.FromDateTime(DateTime.UtcNow.AddMinutes(30))
});
}

#endregion
var nftBalance = await User2TokenContractStub.GetBalance.SendAsync(new GetBalanceInput()
{
Symbol = NftSymbol,
Owner = User2Address
});
nftBalance.Output.Balance.ShouldBe(2);
}

//buy: elf allowance not enough
[Fact]
public async void Buy_Case49_Allowance()
{
await InitializeForestContract();
await PrepareNftData();

var sellPrice = Elf(1000_0000_0000);
var whitePrice = Elf(1_0000_0000);

#region ListWithFixedPrice

{
await UserTokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = NftSymbol, Amount = 5 });

await Seller1ForestContractStub.ListWithFixedPrice.SendAsync(new ListWithFixedPriceInput()
{
Symbol = NftSymbol,
Quantity = 5,
IsWhitelistAvailable = true,
Price = sellPrice,
Whitelists = new WhitelistInfoList()
{
Whitelists =
{
new WhitelistInfo()
{
PriceTag = new PriceTagInfo()
{
TagName = "WHITELIST_TAG",
Price = whitePrice
},
AddressList = new AddressList()
{
Value = { User2Address, User3Address },
}
},
// other WhitelistInfo here
// new WhitelistInfo() {}
}
},
Duration = new ListWithFixedPriceDuration()
{
// start 5min ago
StartTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
// public 10min after
PublicTime = Timestamp.FromDateTime(DateTime.UtcNow).AddSeconds(-2),
DurationMinutes = 1 * 60,
},
});
}

#endregion

#region user2 make offer to user1

{
var errorMessage = "";
try
{
await User2TokenContractStub.Approve.SendAsync(new ApproveInput() { Spender = ForestContractAddress, Symbol = whitePrice.Symbol, Amount = sellPrice.Amount*2-1 });
var executionResult = await BuyerForestContractStub.MakeOffer.SendAsync(new MakeOfferInput()
{
Symbol = NftSymbol,
OfferTo = User1Address,
Quantity = 2,
Price = sellPrice,
ExpireTime = Timestamp.FromDateTime(DateTime.UtcNow.AddMinutes(30))
});
}
catch (Exception e)
{
errorMessage = e.Message;
}
errorMessage.ShouldContain("The allowance you set is less than required. Please reset it.");
}

#endregion
var nftBalance = await User2TokenContractStub.GetBalance.SendAsync(new GetBalanceInput()
{
Symbol = NftSymbol,
Owner = User2Address
});
nftBalance.Output.Balance.ShouldBe(0);
}

[Fact]
//seller: nft allowance not enough
public async void Buy_Case50_Allowance()
{
Expand Down

0 comments on commit 01f1ca4

Please sign in to comment.