diff --git a/priv/json-schemas/aeweb.json b/priv/json-schemas/aeweb.json index bbfebc557..fd4287512 100644 --- a/priv/json-schemas/aeweb.json +++ b/priv/json-schemas/aeweb.json @@ -2,6 +2,17 @@ "$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, @@ -9,7 +20,7 @@ "type": "string" } }, - { + "unpublishedReferenceTx": { "type": "object", "description": "Reference tx of an unpublished website", "properties": { @@ -31,7 +42,7 @@ ], "additionalProperties": false }, - { + "publishedReferenceTx": { "type": "object", "description": "Reference tx of a published website", "properties": { @@ -95,7 +106,8 @@ "required": [ "aewebVersion", "metaData" - ] + ], + "additionalProperties": false } - ] + } } \ No newline at end of file diff --git a/test/archethic/mining/pending_transaction_validation_test.exs b/test/archethic/mining/pending_transaction_validation_test.exs index 97abf6fb8..00f0aa1a9 100644 --- a/test/archethic/mining/pending_transaction_validation_test.exs +++ b/test/archethic/mining/pending_transaction_validation_test.exs @@ -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{ @@ -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