Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AEWeb: schema is more strict #1164

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions priv/json-schemas/aeweb.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"oneOf": [
{
"$ref": "#/$defs/dataTx"
},
{
"$ref": "#/$defs/unpublishedReferenceTx"
},
{
"$ref": "#/$defs/publishedReferenceTx"
}
],
"$defs": {
"dataTx": {
"type": "object",
"description": "Data tx",
"minProperties": 1,
"additionalProperties": {
"type": "string"
}
},
{
"unpublishedReferenceTx": {
"type": "object",
"description": "Reference tx of an unpublished website",
"properties": {
Expand All @@ -31,7 +42,7 @@
],
"additionalProperties": false
},
{
"publishedReferenceTx": {
"type": "object",
"description": "Reference tx of a published website",
"properties": {
Expand Down Expand Up @@ -95,7 +106,8 @@
"required": [
"aewebVersion",
"metaData"
]
],
"additionalProperties": false
}
]
}
}
91 changes: 91 additions & 0 deletions test/archethic/mining/pending_transaction_validation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,45 @@ defmodule Archethic.Mining.PendingTransactionValidationTest do
assert :ok = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end

test "should return :ok when we deploy a aeweb ref transaction with publicationStatus" do
tx =
Transaction.new(:hosting, %TransactionData{
content:
Jason.encode!(%{
"aewebVersion" => 1,
"publicationStatus" => "PUBLISHED",
"metaData" => %{
"index.html" => %{
"encoding" => "gzip",
"hash" => "abcd123",
"size" => 144,
"addresses" => [
Crypto.derive_keypair("seed", 0)
|> elem(0)
|> Crypto.derive_address()
|> Base.encode16()
]
}
}
})
})

assert :ok = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end

test "should return :ok when we deploy a aeweb ref transaction (unpublished)" do
tx =
Transaction.new(:hosting, %TransactionData{
content:
Jason.encode!(%{
"aewebVersion" => 1,
"publicationStatus" => "UNPUBLISHED"
})
})

assert :ok = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end

test "should return :ok when we deploy a aeweb file transaction" do
tx =
Transaction.new(:hosting, %TransactionData{
Expand Down Expand Up @@ -320,6 +359,58 @@ defmodule Archethic.Mining.PendingTransactionValidationTest do

assert {:error, _reason} = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end

test "should return :error when we deploy a wrong aeweb ref transaction (unpublished)" do
tx =
Transaction.new(:hosting, %TransactionData{
content:
Jason.encode!(%{
"aewebVersion" => 1,
"publicationStatus" => "UNPUBLISHED",
"metaData" => %{
"index.html" => %{
"encoding" => "gzip",
"hash" => "abcd123",
"size" => 144,
"addresses" => [
Crypto.derive_keypair("seed", 0)
|> elem(0)
|> Crypto.derive_address()
|> Base.encode16()
]
}
}
})
})

assert {:error, _error} = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end

test "should return :error when it does not respect the schema" do
tx =
Transaction.new(:hosting, %TransactionData{
content:
Jason.encode!(%{
"aewebVersion" => 1,
"hello" => "world",
"metaData" => %{
"index.html" => %{
"encoding" => "gzip",
"hash" => "abcd123",
"size" => 144,
"addresses" => [
Crypto.derive_keypair("seed", 0)
|> elem(0)
|> Crypto.derive_address()
|> Base.encode16()
]
}
}
})
})

assert {:error, _reason} = PendingTransactionValidation.validate(tx, DateTime.utc_now())
end
end

describe "Node" do
Expand Down